Skip to content

Instantly share code, notes, and snippets.

View AshlinRejo's full-sized avatar
🏠
Working from home

Ashlin AshlinRejo

🏠
Working from home
View GitHub Profile
// 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);
}
add_filter('advanced_woo_discount_rules_modify_price_html', function($result, $price_html, $product, $quantity){
// is_page( 'cart' ) -> cart is a page slug
if ( is_page( 'cart' ) || is_cart() ) {
return false;
}
return $result;
}, 10, 4);
add_filter('advanced_woo_discount_rules_select_search_limit', function($search_result_limit){
$search_result_limit = 50;
return $search_result_limit;
}, 10, 1);
function woocommerce_get_price_html_woo_discount_on_sale_compatible($item_price, $product){
$del_pattern = '/<del aria-hidden="true">(.*?)<\/del>/s';
preg_match($del_pattern, $item_price, $matches);
$del_content = isset($matches[1]) ? $matches[1] : '';
$del_content = trim(strip_tags($del_content));
$ins_pattern = "/<ins>(.*?)<\/ins>/s";
preg_match($ins_pattern, $item_price, $matches);
$ins_content = isset($matches[1]) ? $matches[1] : '';
$ins_content = trim(strip_tags($ins_content));