Support

Account

Home Forums General Issues Show Calculated Price on Woocommerce Product Page

Helping

Show Calculated Price on Woocommerce Product Page

  • I’m trying to show a calculated price on the Woocommerce product page, but it doesn’t work. I would like to take the price and multiply it by a ACF field “case_pack”. Here is the code I’m using below:

    add_action( ‘woocommerce_single_product_summary’, ‘display_acf_field_under_price’, 16 );

    function display_acf_field_under_price ( $product ) {

    $price_html = $product->get_price(); //It will return a string
    $case_pack = get_field(‘case_pack’); //Integer
    $float_price = floatval($price_html); //Float
    $float_custom_price = floatval($case_pack); //Float
    $final_case_price = ($float_price + $float_custom_price); //Float
    echo $final_case_price;
    }

  • I figured it out.

    add_action( ‘woocommerce_single_product_summary’, ‘display_custom_field’, 16 );

    function display_custom_field ( ) {
    global $product;
    $pid= $product->get_id();
    $actual_price = floatval($product->get_price());
    $custom_price= floatval(get_post_meta($pid,’case_pack’,true));
    $final_price = $actual_price * $custom_price;
    echo ‘<b>Case Price:</b>’ . ‘ $’ .$final_price;
    }

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Show Calculated Price on Woocommerce Product Page’ is closed to new replies.