Create a dynamic pricing table using dynamic pricing woocommerce plugin
Question
I am using Dynamic pricing plugin and created an mu-plugin for my following custom code. I want to show the the minimum and maximum pricing details on each single product page. It is working fine but can anyone suggest any better approach using WordPress custom query?
<?php
if(is_product){
// we are going to hook this on priority 31, so that it would display below add to cart button.
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
function woocommerce_total_product_price() {
global $woocommerce, $product;
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
//print_r(array_shift( wc_get_product_terms( $product->id, 'current_data', array( 'fields' => 'names' ) ) ));
$testdata = get_post_meta($product_id)['_pricing_rules'][0];
$testdataSerialize = unserialize($testdata);
$tempp = array_shift(array_slice($testdataSerialize, 0, 1));
$tempp = $tempp[rules];
$totalPriceVariations = sizeof($tempp);
$array = array();
if($totalPriceVariations>0){
echo "<table><tr><th>Quantity</th><th>Price</th></tr>";
for($i=1; $i<=$totalPriceVariations; $i++){
$to = $tempp[$i]['to'];
$from = $tempp[$i]['from'];
$more = "more";
if(!empty($to)){
echo "<tr><td>".$tempp[$i]['from']." - ".$tempp[$i]['to']." </td><td>".$tempp[$i]['amount']."".get_woocommerce_currency_symbol()."</td></tr>";
}$endTo = $tempp[$totalPriceVariations]['to'];
$endFrom = $tempp[$totalPriceVariations]['from'];
$endPrice = $tempp[$totalPriceVariations]['amount'];
array_push($array, $endTo, $endFrom, $endPrice);
}
echo "<tr><td>".$array[1]." - more </td><td>".$array[2]."".get_woocommerce_currency_symbol()."</td></tr>";
echo "</table>"; ?>
<?php
}
}
}
?>
0
2 months
0 Answers
5 views
0
Leave an answer
You must login or register to add a new answer .