I am a PHP novice, not good with code at all. I am using this plugin eForm (/) that generates a woocommerce product based on the user's choices. I need the generated product not to exceed $100, but show the actual price if it's below $100. I looked up & found the following code which does what I want partly, but this code always shows the price at $100 even if the actual product price is below $100. I'm looking for help from someone to figure this out. Thanks!
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
if ($price > 100){
$updatedprice = 100;
}
return $updatedprice;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
I am a PHP novice, not good with code at all. I am using this plugin eForm (https://eform.live/) that generates a woocommerce product based on the user's choices. I need the generated product not to exceed $100, but show the actual price if it's below $100. I looked up & found the following code which does what I want partly, but this code always shows the price at $100 even if the actual product price is below $100. I'm looking for help from someone to figure this out. Thanks!
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
if ($price > 100){
$updatedprice = 100;
}
return $updatedprice;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
Share
Improve this question
asked Apr 18, 2020 at 0:58
Tasha BanksTasha Banks
1
1 Answer
Reset to default 0Try this code.
function return_custom_price($price, $product) {
$price = $product->get_regular_price();
if($price > 100){
$updatedprice = 100;
}else{
$updatedprice = $price;
}
return $updatedprice;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);