Created
August 15, 2019 17:52
-
-
Save kish2011/21c7ebfa2b8f9c0ac21a898b4a474b84 to your computer and use it in GitHub Desktop.
Display coupon name in cart page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_cart_coupon', 'woocommerce_cart_coupon_list'); | |
function woocommerce_cart_coupon_list() { | |
$args = array( | |
'posts_per_page' => 5, | |
'orderby' => 'title', | |
'order' => 'desc', | |
'post_type' => 'shop_coupon', | |
'post_status' => 'publish', | |
); | |
$coupons = get_posts( $args ); | |
$coupon_names = array(); | |
foreach ( $coupons as $coupon ) { | |
// Get the name for each coupon post | |
$coupon_name = $coupon->post_title; | |
array_push( $coupon_names, $coupon_name ); | |
} | |
?> | |
<div> | |
Choose your coupon code: | |
<?php | |
foreach ($coupon_names as $key => $value) { | |
echo "<span><b>| " . $value . " |</b></span>\r\n"; | |
} | |
?> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment