Home › Forums › Front-end Issues › WooCommerce price + ACF number field sum › Reply To: WooCommerce price + ACF number field sum
Hi,
The ACF number field will return an integer.
In php you’ll never have some decimal with an integer value, you have to work with float values.
Maybe you could simply try something like this
<?php
$price_html = $product->get_price(); //It will return a string
$x = get_field(‘custom-price’); //Integer
$float_price = floatval($price_html); //Float
$float_custom_price = floatval($x); //Float
$finalPrice = ($float_price + $float_custom_price); //Float
echo $finalPrice;
?>
But this will only display your custom price.
If you want to actually modify your price you have to use woocommerce filters.
In product page :
// Simple, grouped and external products
add_filter(‘woocommerce_product_get_price’, ‘custom_price’, 99, 2 );
add_filter(‘woocommerce_product_get_regular_price’, ‘custom_price’, 99, 2 );
// Variations
add_filter(‘woocommerce_product_variation_get_regular_price’, ‘custom_price’, 99, 2 );
add_filter(‘woocommerce_product_variation_get_price’, ‘custom_price’, 99, 2 );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.