Skip to content

Instantly share code, notes, and snippets.

@kish2011
Created August 15, 2019 17:52
Show Gist options
  • Save kish2011/21c7ebfa2b8f9c0ac21a898b4a474b84 to your computer and use it in GitHub Desktop.
Save kish2011/21c7ebfa2b8f9c0ac21a898b4a474b84 to your computer and use it in GitHub Desktop.
Display coupon name in cart page
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