显示优惠券说明woocommerce [英] Display coupon description woocommerce

查看:54
本文介绍了显示优惠券说明woocommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在购物车页面中应用优惠券后,我试图显示优惠券说明(10%)。

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

要显示总计,我正在使用$ woocommerce->购物车- > cart_contents_total

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

如何显示优惠券描述?

推荐答案

您还没有提到要在何处获得优惠券说明,我已经在购物车总计之前打印了它。

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.

代码:

    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.

这篇关于显示优惠券说明woocommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆