Skip to content

Instantly share code, notes, and snippets.

@sarancartrabbit
sarancartrabbit / Discount rules v2: remove the draft order status
Created February 27, 2024 08:33
Discount rules v2: Remove the draft order status
add_filter('advanced_woo_discount_rules_check_purchase_first_order_status', function ($order_statuses) {
unset($order_statuses['wc-checkout-draft']);
return $order_statuses;
},10,1);
@sarancartrabbit
sarancartrabbit / Woo Discount Rules v2 - Check customized coupon based disable the discount rule
Created February 20, 2024 11:04
Woo Discount Rules v2 - Check customized coupon based disable the discount rule
add_filter('advanced_woo_discount_rules_filter_passed', function($filter_passed, $rule, $product, $sale_badge){
$coupon_applied = in_array('your_coupon_code', WC()->cart->get_applied_coupons());
//'array(1,2)' - give rule id as you needed
if(in_array($rule->getId(), array(1, 2)) && $coupon_applied){
// Add your additional condition here if required
// Your custom logics enter here and return true or false
// true -> Run rule
// false -> Do not run rule
return true;
@sarancartrabbit
sarancartrabbit / Woo Discount Rules: Discount Apply Only Base Price Compatibility for Advanced Product Fields Pro for WooCommerce by StudioWombat
Created February 20, 2024 10:44
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');
@sarancartrabbit
sarancartrabbit / Woo Discount Rules: Remove the you saved text for admin order page
Created February 16, 2024 12:25
Woo Discount Rules: Remove the you saved text for admin order page
add_action('admin_footer', function() {
?>
<style>
.wc-orders-list-table span .awdr-you-saved-text {
display: none !important;
}
</style>
<?php
});
@sarancartrabbit
sarancartrabbit / Woo Discount Rules v3: Add woocommerce coupon value for you saved text
Last active March 11, 2024 05:32
Woo Discount Rules v3: Add woo-commerce coupon value for you saved text
// Cart page add the woocommerce you saved amount
add_filter('wdr_add_woocommerce_amount_saved_text', '__return_true');
// Thankyou and Order page add the woocommerce you saved text
add_filter('wdr_add_woocommerce_amount_saved_text_order_page', '__return_true');
@sarancartrabbit
sarancartrabbit / Woo Discount Rules: Apply discount for both base and options price in Advanced Product Fields Extended for WooCommerce by StudioWombat
Created February 7, 2024 11:58
Woo Discount Rules: Apply discount for both base and options price in Advanced Product Fields Extended for WooCommerce by StudioWombat
add_action('wp_loaded', function() {
remove_all_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price');
},10);
add_action('wp_loaded', function() {
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'])){
$product_price = $cart_item['wapf_item_price']['options_total']+$cart_item['wapf_item_price']['base'];
}
@sarancartrabbit
sarancartrabbit / Woo Discount Rules: Conflict Free Shipping rules
Created February 5, 2024 11:42
Woo Discount Rules: Conflict Free Shipping rules
add_action('wp_loaded', function() {
if (class_exists('\WDRPro\App\Rules\FreeShipping')) {
remove_all_filters('woocommerce_shipping_chosen_method');
remove_all_filters('woocommerce_package_rates');
add_filter('woocommerce_shipping_chosen_method', array('\WDRPro\App\Rules\FreeShipping', 'reset_default_shipping_method_woo_discount'), 100, 2);
add_filter('woocommerce_package_rates', array('\WDRPro\App\Rules\FreeShipping', 'wdrHideShippingWhenFreeIsAvailable'),100);
}
});
@sarancartrabbit
sarancartrabbit / Discount rule: Remove anchor tag button
Created January 30, 2024 08:06
Discount rule: Remove anchor tag button
if(!function_exists('wdr_remove_coupon_anchor_tag_in_cart_html')) {
function wdr_remove_coupon_anchor_tag_in_cart_html($coupon_html, $coupon, $discount_amount_html) {
$coupon_html = str_replace('[Remove]', '', $coupon_html);
return strip_tags($coupon_html);
}
}
add_filter('woocommerce_cart_totals_coupon_html', 'wdr_remove_coupon_anchor_tag_in_cart_html', 10, 3);
if(!function_exists('wdr_remove_coupon_anchor_tag_in_cart_html')) {
@sarancartrabbit
sarancartrabbit / CUW: Add a custom template in thankyou upsells
Last active January 16, 2024 09:49
CUW: Add a custom template in thankyou upsells
add_filter('cuw_templates', function ($templates) {
$templates['products/custom-template-1'] = [
'template' => 'custom-template-1',
'title' => 'You may also like…',
'cta_text' => 'Buy now',
'styles' => [
'template' => ['border-width' => '0', 'border-style' => 'solid', 'border-color' => '#000000', 'background-color' => '', 'padding' => '0'],
'image' => ['size' => '180'],
'title' => ['font-size' => '', 'color' => ''],
'cta' => ['font-size' => '', 'color' => '', 'background-color' => ''],
@sarancartrabbit
sarancartrabbit / Discount rules v2: Disable the recalculate the shipping package
Last active January 12, 2024 14:12
Discount rules v2: Disable the recalculate the shipping package
add_filter('advanced_woo_discount_rules_recalculate_shipping_package', '__return_false');