Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Produce horizontal php table instead of vertical WordPress

  • SOLVED

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;

}

}

Answers (3)

2013-11-08

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

2013-11-08

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 .= '&nbsp;<span class="quantity"> '.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</span>&nbsp;";

} else {

//$tempstring .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."+</td>";

$tempstring2 .= '&nbsp;<span class="quantity">'.$pricing_rule_sets['rules'][$key]['from']."+</span>&nbsp;";

}



$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 .= '&nbsp;<span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span>&nbsp;";



//$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;



}



}

2013-11-08

phppoet answers:

code submitted by fahd murtaza at https://gist.github.com/fahdi/7367626 does display it horizontally . you just need to add &emsp; in <td> to display it properly .

regards