Skip Navigation

Resolved

Resolved in: 4.12.0

Overview of the issue

When using the Advanced Category Pricing feature from the WooCommerce Dynamic Pricing plugin, the discounts are not applied to variable products (only to simple products).

Workaround

We already have a permanent fix for the issue that is waiting for full testing and release. In the meantime, you can use the following workaround to fix the issue on your website:

  1. Make a full backup of your site before proceeding.
  2. Open wp-content/plugins/woocommerce-multilingual/compatibility/class-wcml-dynamic-pricing.php and find line 118.
  3. Replace this:
    
    	public function woocommerce_dynamic_pricing_is_applied_to( $process_discounts, WC_Product $_product, $module_id, $dynamic_pricing, $cat_ids ) {
    		if ( ! $_product || ! $cat_ids || ! $this->has_requirements( $dynamic_pricing ) ) {
    			return $process_discounts;
    		}
    
    		$taxonomy   = $this->get_taxonomy( $dynamic_pricing );
    		$product_id = apply_filters( 'wpml_object_id', $_product->get_id(), 'product', true );
    
    		return is_object_in_term( $product_id, $taxonomy, $this->adjust_cat_ids( $cat_ids, $taxonomy ) );
    	}
    
    

    With

    
    	public function woocommerce_dynamic_pricing_is_applied_to( $process_discounts, WC_Product $_product, $module_id, $dynamic_pricing, $cat_ids ) {
    		if ( ! $_product || ! $cat_ids || ! $this->has_requirements( $dynamic_pricing ) ) {
    			return $process_discounts;
    		}
    
    		$taxonomy   = $this->get_taxonomy( $dynamic_pricing );
    		$product_id = apply_filters( 'wpml_object_id', $_product->get_id(), 'product', true );
                    //fix for variable products
                    if  ($_product->post_type === "product_variation") {
    			$product_id = wc_get_product( $_product->get_parent_id() )->get_id();
    			$product_id = apply_filters( 'wpml_object_id', $product_id, 'product', true );
    			return is_object_in_term( $product_id, $taxonomy, $this->adjust_cat_ids( $cat_ids, $taxonomy ) );
    		}
    
    		return is_object_in_term( $product_id, $taxonomy, $this->adjust_cat_ids( $cat_ids, $taxonomy ) );
    	}