I am using the code to display the coupon codes that are currently published in the shortcode from here.
The code displays a list of published coupon codes on the site.
How to get more? For example:
- Coupon expiry date
- Coupon amount
- Description
Any help would be appreciated.
Here's the code I'm using:
add_shortcode('ac', 'coupon_list' );
function coupon_list() {
$coupon_posts = get_posts( array(
'posts_per_page' => -1,
'orderby' => 'name',
'order' => 'asc',
'post_type' => 'shop_coupon',
'post_status' => 'publish',
) );
$coupon_codes = []; // Initializing
foreach( $coupon_posts as $coupon_post) {
$coupon_codes[] = $coupon_post->post_name;
}
// Display available coupon codes
return implode(', ', $coupon_codes) ; // always use return in a shortcode
}
[1]: https://i.stack.imgur.com/9sYUy.jpg
Lets assume you are storing expirydate, amount as custom fields (say coupon_expirydate, coupon_amount) then,
You you want to show only non-expired coupons just use meta query variable inside arguments of get_posts().