Last active
August 17, 2021 05:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have made a solution for multible Tables with headings. Get the headings dynamicly from a ACF-repeater field....