Skip to content

Instantly share code, notes, and snippets.

@fahdi
Created November 8, 2013 07:50
Show Gist options
  • Save fahdi/7367626 to your computer and use it in GitHub Desktop.
Save fahdi/7367626 to your computer and use it in GitHub Desktop.
function display_bulk_discount_table() {
global $woocommerce, $post, $product;
$array_rule_sets = get_post_meta($post->ID, '_pricing_rules', true);
$_regular_price = get_post_meta($post->ID, '_regular_price', true);
if ($array_rule_sets && is_array($array_rule_sets) && sizeof($array_rule_sets) > 0){
$tempstring .= '<div class="bulk-savings-table">';
$tempstring .= '<span>Bulk Savings</span>';
$tempstring .= '<table>';
$tempstring1 .= '<tr><td>Quantity</td>';
$tempstring2 .='<tr><td>Price</td>';
foreach($array_rule_sets as $pricing_rule_sets)
{
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
if ($pricing_rule_sets['rules'][$key]['to']) {
$tempstring1 .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</td>";
} else {
$tempstring1 .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."+</td>";
}
$finalprice=$_regular_price;
$finalprice = $finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount'];
$tempstring2 .= '<td><span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span></td>";
}
}
$tempstring1 .= '</tr>';
$tempstring2 .= '</tr>';
$tempstring .= $tempstring1 .$tempstring2;
$tempstring .= "</table>";
$tempstring .= "</div>";
echo $tempstring;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment