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
@AshlinRejo
AshlinRejo / Discount rules v2: Fix for applying discount in cart even if it does not matches
Created October 28, 2021 12:47
Discount rules v2: Fix for applying discount in cart even if it does not matches
add_filter('advanced_woo_discount_rules_modify_price_html', function ($do_strikeout){
if(function_exists('is_cart')){
if(is_cart()){
$do_strikeout = false;
}
}
return $do_strikeout;
});
add_filter('advanced_woo_discount_rules_use_sale_badge_percentage_customization', function ($do_strikeout){
@AshlinRejo
AshlinRejo / Discount rules v2: Disable ajax request for loading discount table on other than product detail page
Created October 28, 2021 08:41
Discount rules v2: Disable ajax request for loading discount table on other than product detail page
add_action('advanced_woo_discount_rules_before_initialize', function (){
add_filter('advanced_woo_discount_rules_disable_load_dynamic_bulk_table', function($status) {
$status = "off";
if (is_product()) {
$status = "on";
}
return $status;
});
});
@AshlinRejo
AshlinRejo / Discount rules v2: Disable woocommerce_get_price_html event from other plugins
Created October 26, 2021 12:49
Discount rules v2: Disable woocommerce_get_price_html event from other plugins
add_action('advanced_woo_discount_rules_after_initialize', function (){
if(class_exists('\Wdr\App\Router')){
remove_all_filters('woocommerce_get_price_html');
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtml'), 100, 2);
add_filter('woocommerce_get_price_html', array(\Wdr\App\Router::$manage_discount, 'getPriceHtmlSalePriceAdjustment'), 9, 2);
}
});
@AshlinRejo
AshlinRejo / Discount rules v2: Fix for shipping conflict on auto add
Created October 26, 2021 12:35
Discount rules v2: Fix for shipping conflict on auto add
add_filter('advanced_woo_discount_rules_free_product_cart_item_data', function ($cart_item_data){
remove_all_actions('woocommerce_add_to_cart');
return $cart_item_data;
});
add_filter('advanced_woo_discount_rules_select_search_limit', function($search_result_limit){
$search_result_limit = 50;
return $search_result_limit;
}, 10, 1);
@AshlinRejo
AshlinRejo / Discount rule: Remove coupon remove button based on coupon code
Created October 22, 2021 09:31
Discount rule: Remove coupon remove button based on coupon code
if(!function_exists('fc_woo_applied_coupons_in_cart_html')) {
function fc_woo_applied_coupons_in_cart_html($coupon_html, $coupon, $discount_amount_html) {
$discount_name = 'coupon code';// Enter the coupon name here
//apply only for virtual coupons of woo discount rules
if(method_exists($coupon, 'get_code') && strtoupper($coupon->get_code()) == strtoupper($discount_name)) {
$coupon_html = $discount_amount_html;
}
return $coupon_html;
}
}
@AshlinRejo
AshlinRejo / Discount rule v2: Disable checking wpml language on auto add
Created October 22, 2021 06:19
Discount rule v2: Disable checking wpml language on auto add
add_filter('advanced_woo_discount_rules_check_wpml_language_for_product_before_auto_add', '__return_false');
@AshlinRejo
AshlinRejo / Discount Rules v2: Exclude the Composite product item(WPClever) from discount
Created October 20, 2021 08:28
Discount Rules v2: Exclude the Composite product item(WPClever) from discount
add_filter('advanced_woo_discount_rules_calculate_discount_for_cart_item', function ($calculate_discount, $cart_item){
if(isset($cart_item['wooco_parent_key']) && !empty($cart_item['wooco_parent_key'])){
$calculate_discount = false;
}
return $calculate_discount;
}, 100, 2);
add_filter('advanced_woo_discount_rules_include_cart_item_to_count_quantity', function($take_count, $cart_item){
if(isset($cart_item['wooco_parent_key']) && !empty($cart_item['wooco_parent_key'])){
$take_count = false;
}
@AshlinRejo
AshlinRejo / Discount rule v2: Get matched rule info based on product in product page
Created October 13, 2021 13:25
Discount rule v2: Get matched rule info based on product in product page
if(class_exists('\Wdr\App\Router')) {
global $product;
$discountManager = \Wdr\App\Router::$manage_discount;
$discountCalculator = $discountManager::$calculator;
$rules = $discountCalculator::$rules;
foreach ($rules as $rule) {
if ($rule->isEnabled()) {
$rule_matched = $rule->isFilterPassed($product, true);
if($rule_matched){
@AshlinRejo
AshlinRejo / Discount rules v2: Fix for Cart strikeout conflict due to price strikeout
Created October 13, 2021 12:59
Discount rules v2: Fix for Cart strikeout conflict due to price strikeout
add_filter('advanced_woo_discount_rules_modify_price_html', function ($apply_strikeout){
if(function_exists('is_cart')){
if(is_cart()){
$apply_strikeout = false;
}
}
return $apply_strikeout;
});