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;
}
}
@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