0

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); 
0

Try 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);
| improve this answer | |
  • Thanks for your response. Unfortunately, the product price is always 0 after adding this code – Tasha Banks Apr 18 at 9:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.