Display coupon description woocommerce

孤人 提交于 2019-12-01 11:40:27

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!