Last active
July 27, 2016 08:17
-
-
Save rayflores/df7347397ba65a0e57fd49a41bed5244 to your computer and use it in GitHub Desktop.
exclude variation id from Dynamic Pricing Advanced Category Product Rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* DO NOT ADD SAMPLE PRODUCT WITHIN DYNAMIC DISCOUNT RULES */ | |
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'exclude_sample_products', 10, 2 ); | |
function exclude_sample_products( $include, $product ) { | |
$products_to_exclude = array(); | |
foreach (WC()->cart->cart_contents as $cart_item_key => $cart_item){ | |
if ($cart_item['variation']['attribute_pa_buy-or-try'] == 'try-before-you-buy') { | |
$products_to_exclude[] = $cart_item['variation_id']; | |
} | |
} | |
if ( in_array( $product->variation_id, $products_to_exclude ) ) { | |
$include = false; | |
} | |
return $include; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment