Display coupon description woocommerce

╄→尐↘猪︶ㄣ 提交于 2019-12-19 10:53:03

问题


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?


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/28017767/display-coupon-description-woocommerce

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