How to Apply Coupon Discount on Regular Price in WooCommerce

WooCommerce offers Coupons feature by default. It works very well and is very easy to use. In Woocommerce, by default, if you have a product that is on sale with 30% discount and the user has a 50% off coupon, the 50% discount will be calculated from the on sale price, which is 30% off. So you end up giving more than a 50% discount. Let’s say you have a different ranges of product with different on sale prices. AND you want to run a promotion to give out flat 50% off on all products’ regular price. There is a very simple way to do so.

There are multiple methods by which you can apply coupon discount on regular price in WooCommerce. I am going to show you 2 very easy ones. You just need to add a piece of code. You can either add this code in your child theme’s functions.php file or you can use Code Snippet plugin to do that for you. Just add below piece of code using this plugin. This plugin can be used for all kinds of code tweaking.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price_bi', 10, 1);
function add_custom_price_bi( $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 );
        }
}

Do let me know in the comments if this still works for you.

3 Comments
  1. Reply
    Mojca November 4, 2020 at 9:57 PM

    It works, thank you!!

  2. Reply
    Raul May 6, 2021 at 8:24 PM

    Hi. Does this still work on current versions of Woocommerce and WordPress? Thanks

    • Reply
      Dylan Kelly April 18, 2023 at 10:49 AM

      Yes it does

    Leave a reply

    BrilliantInfo
    Login/Register access is temporary disabled