Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WooCommerce Dynamic Pricing display a table of dynamically generated discounts above the add to cart button
add_action( 'woocommerce_before_add_to_cart_button', 'sd_display_bulk_discount_table' );
function sd_display_bulk_discount_table() {
global $woocommerce, $post, $product;
$array_rule_sets = get_post_meta( $post->ID, '_pricing_rules', true );
if ( $array_rule_sets && is_array( $array_rule_sets ) && sizeof( $array_rule_sets ) > 0 ) {
$tempstring .= '<table>';
$tempstring .= '<th>Quantity</th><th>Discount</th>';
foreach( $array_rule_sets as $pricing_rule_sets ) {
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
switch ( $pricing_rule_sets['rules'][$key]['type'] ) {
case 'percentage_discount':
$woosymbol = '%';
case 'price_discount':
$woosymbol = get_woocommerce_currency_symbol();
$tempstring .= '<tr>';
$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']." - ".$pricing_rule_sets['rules'][$key]['to']."</td>";
$tempstring .= '<td><span class="amount">' . $pricing_rule_sets['rules'][$key]['amount'] . "" . $woosymbol . "</span></td>";
$tempstring .= '</tr>';
$tempstring .= "</table>";
echo $tempstring;
Copy link

Cronbread commented May 25, 2016

Outputs tables for products with multiple variables nicely, but without variable-combination "headings". Is there a simple way to preface each table with variable-combination names so that the long list of prices is broken into several tables? Cheers.

Copy link

onegent commented Jul 5, 2016

Great! Works for me, thank you!

Copy link

johnzhel commented Aug 2, 2016

Great! Works for me, too. But this only works for percentage discount. It does not work for fixed price or price discount. Can you advise how to make it work for those cases? Thanks!

Copy link

stuartduff commented Aug 25, 2016

I have now created a plugin that adds a discount table for bulk pricing and special offers which you can download from below.

cc: @Cronbread @onegent

Copy link

marquesart commented May 30, 2018

Have made a solution for multible Tables with headings. Get the headings dynamicly from a ACF-repeater field....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment