Below, you’ll find a detailed guide on how to add the Smart Coupons For WooCommerce Coupons Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Smart Coupons For WooCommerce Coupons Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Smart Coupons For WooCommerce Coupons Plugin and the shortcodes it provides:
"Smart Coupons For WooCommerce Coupons is an intuitive plugin designed to streamline coupon management for your WooCommerce store. It facilitates easy creation, distribution, and tracking of promotional codes."
- [wt-smart-coupon]
Smart Coupons For WooCommerce Coupons [wt-smart-coupon] Shortcode
The ‘wt-smart-coupon’ shortcode from the WT Smart Coupons for WooCommerce plugin is designed to display specific coupon details on the page. It verifies the coupon’s ID, status, and type. If valid, it retrieves the coupon’s title, metadata, and HTML structure. It also ensures the coupon’s CSS is added only once to avoid duplication.
Shortcode: [wt-smart-coupon]
Parameters
Here is a list of all possible wt-smart-coupon shortcode parameters and attributes:
id
– The specific identification number for the coupon
Examples and Usage
Basic example – The shortcode displays a specific coupon by its ID.
[wt-smart-coupon id=2 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wt-smart-coupon]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('wt-smart-coupon', array($this, 'display_coupon'));
Shortcode PHP function:
function display_coupon($atts)
{
if(!$atts['id'] || 'publish' !== get_post_status($atts['id']) || 'shop_coupon' !== get_post_type($atts['id']))
{
return __('Invalid coupon', 'wt-smart-coupons-for-woocommerce');
}
$coupon_title = get_the_title($atts['id']);
$coupon = new WC_Coupon($atts['id']);
$coupon_data = Wt_Smart_Coupon_Public::get_coupon_meta_data($coupon);
$coupon_data['display_on_page'] = 'by_shortcode';
$coupon_html = '';
$include_coupon_css = false;
if(!self::$coupon_css_added) //css not added
{
ob_start();
Wt_Smart_Coupon_Public::print_coupon_default_css();
$coupon_html = ob_get_clean(); //add css
$include_coupon_css = true; //add template css along with HTML
self::$coupon_css_added = true; //mark it as added to avoid duplicate
}
$coupon_html .= Wt_Smart_Coupon_Public::get_coupon_html($coupon, $coupon_data, "available_coupon", $include_coupon_css);
return $coupon_html;
}
Code file location:
wt-smart-coupons-for-woocommerce/wt-smart-coupons-for-woocommerce/common/modules/coupon_shortcode/coupon_shortcode.php
Conclusion
Now that you’ve learned how to embed the Smart Coupons For WooCommerce Coupons Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply