Last active
July 16, 2024 13:01
-
-
Save braddalton/9caea45fbfe91b9416e954cc64494b48 to your computer and use it in GitHub Desktop.
Quantity Discounts Table Code in WooCommerce https://wpsites.net/wordpress-tutorials/how-to-add-a-wc-quantity-discount-table-using-code/ Premium version https://wpsites.net/product/quantity-discount-table-plugin-for-woocommerce/
This file contains 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_single_product_summary', 'display_discount_table', 20 ); | |
function display_discount_table() { | |
global $product; | |
if ( ! $product->is_type( 'simple' ) ) { | |
return; | |
} | |
$discounts = [ | |
5 => '5%', | |
10 => '10%', | |
25 => '15%', | |
50 => '20%', | |
100 => '25%', | |
250 => '27%', | |
500 => '29%' | |
]; | |
echo '<table class="discount-table">'; | |
echo '<thead><tr><th>Quantity</th><th>Discount</th></tr></thead>'; | |
echo '<tbody>'; | |
foreach ( $discounts as $quantity => $discount ) { | |
echo '<tr><td>' . $quantity . '</td><td>' . $discount . '</td></tr>'; | |
} | |
echo '</tbody>'; | |
echo '</table>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment