最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Woocommerce product price change

programmeradmin5浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 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);
发布评论

评论列表(0)

  1. 暂无评论