问题
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