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?

// 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();
    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";
    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>"; ?>



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.