Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

shortcode to display number of products sold by coupon code

I have coupon "coupon-test"

I have this snippets to show the number of usage for the coupons

function simple_function_1() {
    
    $coupon_code = 'coupon-test';
    global $woocommerce;
    $coupon_data = new WC_Coupon($coupon_code);
    echo ($coupon_data->usage_count);// return number of remaining coupons
}
add_shortcode( 'own_shortcode1', 'simple_function_1' );

I want to make shortcode to display number of usage for coupon and number of products sold by coupon

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Output from shortcode functions is presented to WordPress’s page construction code by doing return $theResult;, not via echo $theResult;. Your code uses echo, though.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading