Hi this code, produce a vertical table of data, how do I get it to produce horizontal instead so:
current:
Quantity Price
data data
data data
data data
required:
Quantity data data data
Price data data data
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>';
$tempstring .= '<th>Quantity</th>
<th>Price</th>';
foreach($array_rule_sets as $pricing_rule_sets)
{
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
$tempstring .= '<tr>';
if ($pricing_rule_sets['rules'][$key]['to']) {
$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</td>";
} else {
$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."+</td>";
}
$finalprice=$_regular_price;
$finalprice = $finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount'];
$tempstring .= '<td><span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span></td>";
$tempstring .= '</tr>';
}
}
$tempstring .= "</table>";
$tempstring .= "</div>";
echo $tempstring;
}
}
Fahad Murtaza answers:
That should do
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;
}
}
Fahad Murtaza comments:
https://gist.github.com/fahdi/7367626 has the properly formatted code.
Fahad Murtaza comments:
Thanks @phppoet, I had no way to test it. Just coded it blindly :)
willcm comments:
works perfectly - thanks
Arnav Joy answers:
try this
<?php
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>';
foreach($array_rule_sets as $pricing_rule_sets)
{
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
//$tempstring .= '<tr>';
if ($pricing_rule_sets['rules'][$key]['to']) {
//$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</td>";
$tempstring2 .= ' <span class="quantity"> '.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</span> ";
} else {
//$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."+</td>";
$tempstring2 .= ' <span class="quantity">'.$pricing_rule_sets['rules'][$key]['from']."+</span> ";
}
$finalprice=$_regular_price;
$finalprice = $finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount'];
//$tempstring .= '<td><span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span></td>";
$tempstring3 .= ' <span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span> ";
//$tempstring .= '</tr>';
}
}
$tempstring .= '<tr><th>Quantity</th><td>'.$tempstring2.'</td></tr>';
$tempstring .= '<tr><th>Price</th><td>'.$tempstring3.'</td></tr>';
$tempstring .= "</table>";
$tempstring .= "</div>";
echo $tempstring;
}
}
phppoet answers:
code submitted by fahd murtaza at https://gist.github.com/fahdi/7367626 does display it horizontally . you just need to add   in <td> to display it properly .
regards