Search code examples
wordpresswoocommercecartcoupon

Display coupon description woocommerce?


I wondered in anyone could help me figure out how to display the coupon description underneath the coupon title in a WooCommerce cart? For example the title is the coupon code (COUPONCODE1234) but it would be useful if underneath or immediately after it displayed how much of a discount this provides i.e. '15% OFF'.

Here's the theme I'm using. You'll need to add a product to the cart to view the cart pane: http://demo.lollum.com/nantes/shop/shop/

I've tried the solution underneath but it doesn't work :( Display coupon description woocommerce

Hope someone can help point me in the right direction!


Solution

  • Assuming that you are using WooCommerce coupon and discount type is "Cart % Discount".

    You can use the " woocommerce_cart_totals_coupon_html " filter to display the discount percentage after the coupon code on cart page.

    function my_test($value, $coupon)
    {
        if($coupon->discount_type == 'percent' && !empty($coupon->coupon_amount))
        {
            $amt = "<p>{$coupon->coupon_amount}% OFF</p>";   
        }
    
        return $value.$amt;
    }
    add_filter('woocommerce_cart_totals_coupon_html','my_test',10,2);
    

    It will display the discount as shown in an image.

    Cart Page