Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/eeca0adbd4942869bd6a8ed78a1620bd to your computer and use it in GitHub Desktop.
Save sarancartrabbit/eeca0adbd4942869bd6a8ed78a1620bd to your computer and use it in GitHub Desktop.
Woo Discount Rules: Discount Apply Only Base Price Compatibility for Advanced Product Fields Pro for WooCommerce by StudioWombat
add_action('advanced_woo_discount_rules_after_initialize', function() {
if(class_exists('\Wdr\App\Router')){
remove_action('woocommerce_before_calculate_totals', array(\Wdr\App\Router::$manage_discount, 'applyCartProductDiscount'), 1000);
add_action('woocommerce_before_calculate_totals', array(\Wdr\App\Router::$manage_discount, 'applyCartProductDiscount'), 10000);
}
});
add_action('plugins_loaded', function() {
if(class_exists('\Wdr\App\Router')){
remove_all_filters('advanced_woo_discount_rules_cart_strikeout_price_html');
}
}, 100);
if (!function_exists('advanced_woo_discount_rules_get_add_on_price_with_discount')) {
function advanced_woo_discount_rules_get_add_on_price_with_discount($product_price, $product, $quantity, $cart_item, $calculate_discount_from) {
if(isset($cart_item['wapf_item_price']) && !empty($cart_item['wapf_item_price'])){
if(isset($cart_item['wapf_item_price']['options_total']) && isset($cart_item['wapf_item_price']['base'])){
if ( class_exists('\Wdr\App\Helpers\Woocommerce')) {
$product_id = \Wdr\App\Helpers\Woocommerce::getProductId($product);
if($calculate_discount_from == "regular_price"){
$price = get_post_meta( $product_id, '_regular_price', true);
}else{
$price = get_post_meta( $product_id, '_price', true);
}
}
$product_price = $cart_item['wapf_item_price']['options_total']+$price;
}
}
return $product_price;
}
add_filter('advanced_woo_discount_rules_product_original_price_on_before_calculate_discount', 'advanced_woo_discount_rules_get_add_on_price_with_discount', 100, 5);
add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', 'advanced_woo_discount_rules_get_add_on_price_with_discount', 100, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment