Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartduff/6f4f17205b847868478dd8164885d3f3 to your computer and use it in GitHub Desktop.
Save stuartduff/6f4f17205b847868478dd8164885d3f3 to your computer and use it in GitHub Desktop.
WooCommerce Dynamic Pricing display a table of dynamically generated discounts above the add to cart button http://cld.wthms.co/1ksKo/4u9gVw0f
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 = '%';
break;
case 'price_discount':
$woosymbol = get_woocommerce_currency_symbol();
break;
}
$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;
}
}
@Cronbread
Copy link

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.

@onegent
Copy link

onegent commented Jul 5, 2016

Great! Works for me, thank you!

@johnzhel
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!

@stuartduff
Copy link
Author

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.

https://github.com/stuartduff/woocommerce-dynamic-pricing-table

cc: @Cronbread @onegent

@marquesart
Copy link

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