Answer the question
In order to leave comments, you need to log in
Why can't I get the value from each Advanced Custom Fields product?
Good day, I have an int store built on Woocommerce, I have a group of fields created using Advanced Custom Fields, I made the display of this group of fields in each product and set the default value to, say, 1500. I import products using WP All Import and these imported products are displayed with a zero price, in function.php I wrote a code that changes the price, according to the formula I need, I take one of the values \u200b\u200bfrom this very group of fields from each product, I found the reason for displaying a zero price - the value (1500), which is set by default , is entered into the formula as 0, that is, now I will show an abbreviated formula for a good example:
function my_price($price, $_product){
$number = get_field('number', $post->ID);
$new_price = $number ;
return $new_price;
}
add_filter('woocommerce_product_get_price', 'my_price',100,2);
Answer the question
In order to leave comments, you need to log in
Well, the first thing that rushed was the absence global $post;
at the beginning of the function. Although you get the $_product variable in the function arguments, this is a product object, then take $_product->get_id()
it from it, and then $post is not needed.
What works, Are the products with the correct price unloaded?
Ran your code, it works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question