I'm not sure if this is the best method to go about this, but here is my problem:

I want to display the discount percentage on an item (i.e. Sales Price - Regular Price / Regular Price * 100)

Woocommerce doesn't natively store that info, it only stores sales price and regular price.

I'm looking to display this in Revolution Slider, so I want to have it as meta values.

I'm not sure if this is the best approach.

Further, I wouldn't be sure where to start with trying to create a new entry in wp_postmeta.

Would I be looking at creating a small plugin or do you think there's a simpler way to achieve what I want?

  • I wouldn't save this information in post meta, but cause if the numbers change you would need to update the post meta too. What are the options you can use in the Revolution Slider, can you use a shortcode in it? Something like [my_display_price sale_price="9.99" regular_price="14.99"] and then write your shortcode handler to use those parameters? – stillatmylinux Feb 16 '17 at 22:28
  • Perfect. Cheers. – Barton Keyes Feb 17 '17 at 2:20

With thanks to stillatmylinux for the steer.

Here's the code I used in the end should anyone need something similar

// Woocommerce Percentage Saved

function percentager_shortcode($atts)
// override default attributes with user attributes
$percentager_atts = shortcode_atts([
                                 'reg' => '500',
                                 'sale' => '200'
                             ], $atts);
                             $added_up = round( ( ( $percentager_atts['reg'] - $percentager_atts['sale'] ) / $percentager_atts['reg'] ) * 100 );

// start output
$o = '';

// Words
$o .=  esc_html__($added_up, 'percentager') . '% Off';

// return output
return $o;

function percentager_shortcodes_init()
add_shortcode('percentager', 'percentager_shortcode');

add_action('init', 'percentager_shortcodes_init');

Then the shortcode used in Revolution slider:

[percentager reg="{{meta:_regular_price}}" sale="{{meta:_sale_price}}"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.