1

I am trying to display coupon description once the coupon is applied (10%) in cart page.

To display Total I am using $woocommerce->cart->cart_contents_total

How do I display coupon description?

itsMe
  • 623
  • 3
  • 9
  • 23

2 Answers2

10

As you have not mentioned where do you want to have coupon description, I have printed it just before Cart Total.

If you want to have it on different place, you can modify action. You can find it from here.

Code:

    add_action('woocommerce_before_cart_totals', 'apply_product_on_coupon');
    function apply_product_on_coupon() {
        global $woocommerce;

        if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
             $my_coupon = $woocommerce->cart->get_coupons() ;
             foreach($my_coupon as $coupon){

                if ( $post = get_post( $coupon->id ) ) {
                        if ( !empty( $post->post_excerpt ) ) {
                            echo "<span class='coupon-name'><b>".$coupon->code."</b></span>";
                            echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
                        }
                }
            }
        }
    }

Let me know if you have any doubts.

Rohil_PHPBeginner
  • 6,002
  • 2
  • 21
  • 32
  • This works, but everytime there is an ajax refresh, it loads the excerpt... so I am having duplicates... any way to only fire this one time? – MuhuPower Aug 17 '19 at 00:39
1

This plugin create shortcode to display coupons info. One of them is [coupon_description].

https://wordpress.org/plugins/woocommerce-coupon-shortcodes/

BenB
  • 2,747
  • 3
  • 29
  • 54