Support » Plugin: WooCommerce » Coupon Applied on Regular Price

  • Resolved Daniel Chan

    (@danielchan23)


    Hi there,

    I need help on applying the coupon on the regular price instead of the sales price of the product.

    For example, I have a product that has Bundle of Two discount. So when I use the coupon code ‘ssxvisa15’, it grants a 15% off. I want the 15% off to apply on the regular price of the bundle instead of the discounted sales price.

    I previously used this code snippet, but it no longer works now :

    add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1);
    function add_custom_price( $cart_object) {
    
        global $woocommerce;
    
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        $coupon = False;
    
        if ($coupons = WC()->cart->get_applied_coupons()  == False ) 
          $coupon = False;
        else {
            foreach ( WC()->cart->get_applied_coupons() as $code ) {
              $coupons1 = new WC_Coupon( $code );
              if ($coupons1->type == 'percent_product' || $coupons1->type == 'percent')
                $coupon = True;
            }
        }
    
        if ($coupon == True)
            foreach ( $cart_object->get_cart() as $cart_item ) 
            {
                $price = $cart_item['data']->regular_price;
                $cart_item['data']->set_price( $price );
            }
    }

    Thanks for your help!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.