-
-
Save AshlinRejo/b21eb161a83c8def3b5b38a0c9542701 to your computer and use it in GitHub Desktop.
Discount Rules: Override Cart page overrides (by increase priority to higher and suppress some hooks)
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
// To override Cart Page Overrides (increase priority to higher) | |
add_action('wp_loaded', 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'), PHP_INT_MAX); | |
remove_all_filters('woocommerce_cart_item_price'); | |
add_filter('woocommerce_cart_item_price', array(\Wdr\App\Router::$manage_discount, 'getCartPriceHtml'), 1000, 3); | |
if (has_filter('woocommerce_cart_item_subtotal', array(\Wdr\App\Router::$manage_discount, 'getCartProductSubtotalPriceHtml'))) { | |
add_filter('woocommerce_cart_item_subtotal', array(\Wdr\App\Router::$manage_discount, 'getCartProductSubtotalPriceHtml'), 10, 3); | |
} | |
} | |
}, 100); | |
/* Show sale & regular price on the checkout page */ | |
add_filter("woocommerce_cart_item_subtotal", "al_display_discount_price_override_by_discount_rule", 11, 3); | |
function al_display_discount_price_override_by_discount_rule($product_price, $cart_item, $cart_item_key) | |
{ | |
$regular_price = wc_price( $cart_item['data']->get_regular_price() ); | |
if( $product_price != $regular_price ) | |
{ | |
if(isset( $cart_item['cartflows_bump'] ) && 1 == $cart_item['cartflows_bump']) | |
{ | |
$product_price = wc_format_sale_price( $cart_item['data']->get_regular_price(), $cart_item['custom_price'] ); | |
}else{ | |
$product_price = wc_format_sale_price( $cart_item['data']->get_regular_price(), $cart_item['data']->get_price() ); | |
} | |
} | |
return $product_price; | |
} | |
/* Show sale & regular price on the checkout page */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment