显示优惠券说明woocommerce

its*_*sMe 1 wordpress cart coupon woocommerce

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

显示总计我使用$ woocommerce-> cart-> cart_contents_total

如何显示优惠券说明?

Roh*_*ner 10

由于你没有提到你想在哪里有优惠券描述,我在Cart Total之前就已经打印过.

如果您想将它放在不同的地方,您可以修改action.你可以从这里找到它.

码:

    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>";
                        }
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果您有任何疑问,请告诉我.