X7ROOT File Manager
Current Path:
/home/gfecatvj/4abetter.us/wp-content/plugins/woocommerce/includes
home
/
gfecatvj
/
4abetter.us
/
wp-content
/
plugins
/
woocommerce
/
includes
/
📁
..
📁
abstracts
📁
admin
📁
blocks
📄
class-wc-ajax.php
(119.74 KB)
📄
class-wc-auth.php
(12.69 KB)
📄
class-wc-autoloader.php
(3.32 KB)
📄
class-wc-background-emailer.php
(4.58 KB)
📄
class-wc-background-updater.php
(3.45 KB)
📄
class-wc-brands-brand-settings-manager.php
(1.78 KB)
📄
class-wc-brands-coupons.php
(6.89 KB)
📄
class-wc-brands.php
(32.93 KB)
📄
class-wc-breadcrumb.php
(9.49 KB)
📄
class-wc-cache-helper.php
(12.65 KB)
📄
class-wc-cart-fees.php
(3.37 KB)
📄
class-wc-cart-session.php
(21.18 KB)
📄
class-wc-cart-totals.php
(28.48 KB)
📄
class-wc-cart.php
(71.23 KB)
📄
class-wc-checkout.php
(50.15 KB)
📄
class-wc-cli.php
(3.34 KB)
📄
class-wc-comments.php
(22.63 KB)
📄
class-wc-countries.php
(49.16 KB)
📄
class-wc-coupon.php
(39.93 KB)
📄
class-wc-customer-download-log.php
(3.37 KB)
📄
class-wc-customer-download.php
(10.34 KB)
📄
class-wc-customer.php
(32.54 KB)
📄
class-wc-data-exception.php
(1.29 KB)
📄
class-wc-data-store.php
(6.59 KB)
📄
class-wc-datetime.php
(2.26 KB)
📄
class-wc-deprecated-action-hooks.php
(6.59 KB)
📄
class-wc-deprecated-filter-hooks.php
(7.34 KB)
📄
class-wc-discounts.php
(36.64 KB)
📄
class-wc-download-handler.php
(28.37 KB)
📄
class-wc-emails.php
(38.15 KB)
📄
class-wc-embed.php
(4.24 KB)
📄
class-wc-form-handler.php
(45.89 KB)
📄
class-wc-frontend-scripts.php
(29.76 KB)
📄
class-wc-geo-ip.php
(30.41 KB)
📄
class-wc-geolite-integration.php
(1.99 KB)
📄
class-wc-geolocation.php
(11.32 KB)
📄
class-wc-https.php
(4.33 KB)
📄
class-wc-install.php
(108.25 KB)
📄
class-wc-integrations.php
(1.28 KB)
📄
class-wc-log-levels.php
(3.9 KB)
📄
class-wc-logger.php
(9.38 KB)
📄
class-wc-meta-data.php
(2.21 KB)
📄
class-wc-order-factory.php
(8.52 KB)
📄
class-wc-order-item-coupon.php
(4.08 KB)
📄
class-wc-order-item-fee.php
(9.21 KB)
📄
class-wc-order-item-meta.php
(5.8 KB)
📄
class-wc-order-item-product.php
(15.84 KB)
📄
class-wc-order-item-shipping.php
(8.8 KB)
📄
class-wc-order-item-tax.php
(6.49 KB)
📄
class-wc-order-item.php
(18.54 KB)
📄
class-wc-order-query.php
(2.55 KB)
📄
class-wc-order-refund.php
(5.99 KB)
📄
class-wc-order.php
(75.39 KB)
📄
class-wc-payment-gateways.php
(15.73 KB)
📄
class-wc-payment-tokens.php
(6.24 KB)
📄
class-wc-post-data.php
(34.55 KB)
📄
class-wc-post-types.php
(32 KB)
📄
class-wc-privacy-background-process.php
(1.79 KB)
📄
class-wc-privacy-erasers.php
(13.61 KB)
📄
class-wc-privacy-exporters.php
(14.69 KB)
📄
class-wc-privacy.php
(17.22 KB)
📄
class-wc-product-attribute.php
(6.97 KB)
📄
class-wc-product-download.php
(12.25 KB)
📄
class-wc-product-external.php
(4.98 KB)
📄
class-wc-product-factory.php
(3.88 KB)
📄
class-wc-product-grouped.php
(6.53 KB)
📄
class-wc-product-query.php
(2.28 KB)
📄
class-wc-product-simple.php
(2.7 KB)
📄
class-wc-product-variable.php
(22.41 KB)
📄
class-wc-product-variation.php
(20.18 KB)
📄
class-wc-query.php
(33.36 KB)
📄
class-wc-rate-limiter.php
(4 KB)
📄
class-wc-regenerate-images-request.php
(7.74 KB)
📄
class-wc-regenerate-images.php
(15.44 KB)
📄
class-wc-register-wp-admin-settings.php
(5.05 KB)
📄
class-wc-rest-authentication.php
(21.55 KB)
📄
class-wc-rest-exception.php
(276 B)
📄
class-wc-session-handler.php
(22.54 KB)
📄
class-wc-shipping-rate.php
(9.34 KB)
📄
class-wc-shipping-zone.php
(13.08 KB)
📄
class-wc-shipping-zones.php
(4.01 KB)
📄
class-wc-shipping.php
(12.85 KB)
📄
class-wc-shortcodes.php
(18.82 KB)
📄
class-wc-structured-data.php
(23.73 KB)
📄
class-wc-tax.php
(38.31 KB)
📄
class-wc-template-loader.php
(20.28 KB)
📄
class-wc-tracker.php
(49.37 KB)
📄
class-wc-validation.php
(5.79 KB)
📄
class-wc-webhook.php
(29.41 KB)
📄
class-woocommerce.php
(59.56 KB)
📁
cli
📁
customizer
📁
data-stores
📁
emails
📁
export
📁
gateways
📁
import
📁
integrations
📁
interfaces
📁
legacy
📁
libraries
📁
log-handlers
📁
payment-tokens
📁
product-usage
📁
queue
📁
react-admin
📁
rest-api
📁
shipping
📁
shortcodes
📁
theme-support
📁
tracks
📁
traits
📁
walkers
📄
wc-account-functions.php
(14.11 KB)
📄
wc-attribute-functions.php
(21.85 KB)
📄
wc-brands-functions.php
(4.17 KB)
📄
wc-cart-functions.php
(21.05 KB)
📄
wc-conditional-functions.php
(15.53 KB)
📄
wc-core-functions.php
(86.78 KB)
📄
wc-coupon-functions.php
(5.55 KB)
📄
wc-deprecated-functions.php
(38.12 KB)
📄
wc-formatting-functions.php
(49.85 KB)
📄
wc-notice-functions.php
(8.08 KB)
📄
wc-order-functions.php
(42.75 KB)
📄
wc-order-item-functions.php
(5.03 KB)
📄
wc-order-step-logger-functions.php
(5.01 KB)
📄
wc-page-functions.php
(9.43 KB)
📄
wc-product-functions.php
(57.36 KB)
📄
wc-rest-functions.php
(13.92 KB)
📄
wc-stock-functions.php
(17.13 KB)
📄
wc-template-functions.php
(138.36 KB)
📄
wc-template-hooks.php
(12.84 KB)
📄
wc-term-functions.php
(23.84 KB)
📄
wc-update-functions.php
(94.71 KB)
📄
wc-user-functions.php
(34.2 KB)
📄
wc-webhook-functions.php
(5.77 KB)
📄
wc-widget-functions.php
(2.01 KB)
📁
wccom-site
📁
widgets
Editing: class-wc-brands-coupons.php
<?php declare( strict_types = 1); use Automattic\WooCommerce\Enums\ProductType; /** * WC_Brands_Coupons class. * * Important: For internal use only by the Automattic\WooCommerce\Internal\Brands package. * * @version 9.4.0 */ class WC_Brands_Coupons { const E_WC_COUPON_EXCLUDED_BRANDS = 301; /** * Constructor */ public function __construct() { // Coupon validation and error handling. add_filter( 'woocommerce_coupon_is_valid', array( $this, 'is_coupon_valid' ), 10, 3 ); add_filter( 'woocommerce_coupon_is_valid_for_product', array( $this, 'is_valid_for_product' ), 10, 3 ); add_filter( 'woocommerce_coupon_error', array( $this, 'brand_exclusion_error' ), 10, 2 ); } /** * Validate the coupon based on included and/or excluded product brands. * * If one of the following conditions are met, an exception will be thrown and * displayed as an error notice on the cart page: * * 1) Coupon has a brand requirement but no products in the cart have the brand. * 2) All products in the cart match the brand exclusion rule. * 3) For a cart discount, there is at least one product in cart that matches exclusion rule. * * @throws Exception Throws Exception for invalid coupons. * @param bool $valid Whether the coupon is valid. * @param WC_Coupon $coupon Coupon object. * @param WC_Discounts $discounts Discounts object. * @return bool $valid True if coupon is valid, otherwise Exception will be thrown. */ public function is_coupon_valid( $valid, $coupon, $discounts = null ) { $this->set_brand_settings_on_coupon( $coupon ); // Only check if coupon has brand restrictions on it. $brand_coupon_settings = WC_Brands_Brand_Settings_Manager::get_brand_settings_on_coupon( $coupon ); $brand_restrictions = ! empty( $brand_coupon_settings['included_brands'] ) || ! empty( $brand_coupon_settings['excluded_brands'] ); if ( ! $brand_restrictions ) { return $valid; } $included_brands_match = false; $excluded_brands_matches = 0; $items = $discounts->get_items(); foreach ( $items as $item ) { $product_brands = $this->get_product_brands( $this->get_product_id( $item->product ) ); if ( ! empty( array_intersect( $product_brands, $brand_coupon_settings['included_brands'] ) ) ) { $included_brands_match = true; } if ( ! empty( array_intersect( $product_brands, $brand_coupon_settings['excluded_brands'] ) ) ) { ++$excluded_brands_matches; } } // 1) Coupon has a brand requirement but no products in the cart have the brand. if ( ! $included_brands_match && ! empty( $brand_coupon_settings['included_brands'] ) ) { throw new Exception( $coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ), WC_Coupon::E_WC_COUPON_NOT_APPLICABLE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } // 2) All products in the cart match brand exclusion rule. if ( count( $items ) === $excluded_brands_matches ) { throw new Exception( __( 'Sorry, this coupon is not applicable to the brands of selected products.', 'woocommerce' ), self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } // 3) For a cart discount, there is at least one product in cart that matches exclusion rule. if ( $coupon->is_type( 'fixed_cart' ) && $excluded_brands_matches > 0 ) { throw new Exception( __( 'Sorry, this coupon is not applicable to the brands of selected products.', 'woocommerce' ), self::E_WC_COUPON_EXCLUDED_BRANDS ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped } return $valid; } /** * Check if a coupon is valid for a product. * * This allows percentage and product discounts to apply to only * the correct products in the cart. * * @param bool $valid Whether the product should get the coupon's discounts. * @param WC_Product $product WC Product Object. * @param WC_Coupon $coupon Coupon object. * @return bool $valid */ public function is_valid_for_product( $valid, $product, $coupon ) { if ( ! is_a( $product, 'WC_Product' ) ) { return $valid; } $this->set_brand_settings_on_coupon( $coupon ); $product_id = $this->get_product_id( $product ); $product_brands = $this->get_product_brands( $product_id ); // Check if coupon has a brand requirement and if this product has that brand attached. $brand_coupon_settings = WC_Brands_Brand_Settings_Manager::get_brand_settings_on_coupon( $coupon ); if ( ! empty( $brand_coupon_settings['included_brands'] ) && empty( array_intersect( $product_brands, $brand_coupon_settings['included_brands'] ) ) ) { return false; } // Check if coupon has a brand exclusion and if this product has that brand attached. if ( ! empty( $brand_coupon_settings['excluded_brands'] ) && ! empty( array_intersect( $product_brands, $brand_coupon_settings['excluded_brands'] ) ) ) { return false; } return $valid; } /** * Display a custom error message when a cart discount coupon does not validate * because an excluded brand was found in the cart. * * @param string $err The error message. * @param string $err_code The error code. * @return string */ public function brand_exclusion_error( $err, $err_code ) { if ( self::E_WC_COUPON_EXCLUDED_BRANDS !== $err_code ) { return $err; } return __( 'Sorry, this coupon is not applicable to the brands of selected products.', 'woocommerce' ); } /** * Get a list of brands that are assigned to a specific product * * @param int $product_id Product id. * @return array brands */ private function get_product_brands( $product_id ) { return wp_get_post_terms( $product_id, 'product_brand', array( 'fields' => 'ids' ) ); } /** * Set brand settings as properties on coupon object. These properties are * lists of included product brand IDs and list of excluded brand IDs. * * @param WC_Coupon $coupon Coupon object. * * @return void */ private function set_brand_settings_on_coupon( $coupon ) { $brand_coupon_settings = WC_Brands_Brand_Settings_Manager::get_brand_settings_on_coupon( $coupon ); if ( ! empty( $brand_coupon_settings['included_brands'] ) && ! empty( $brand_coupon_settings['excluded_brands'] ) ) { return; } $included_brands = get_post_meta( $coupon->get_id(), 'product_brands', true ); if ( empty( $included_brands ) ) { $included_brands = array(); } $excluded_brands = get_post_meta( $coupon->get_id(), 'exclude_product_brands', true ); if ( empty( $excluded_brands ) ) { $excluded_brands = array(); } // Store these for later to avoid multiple look-ups. WC_Brands_Brand_Settings_Manager::set_brand_settings_on_coupon( $coupon ); } /** * Returns the product (or variant) ID. * * @param WC_Product $product WC Product Object. * @return int Product ID */ private function get_product_id( $product ) { return $product->is_type( ProductType::VARIATION ) ? $product->get_parent_id() : $product->get_id(); } } new WC_Brands_Coupons();
Upload File
Create Folder