محصولات متغیر در ووکامرس

ma30ud

تازه وارد
سلام

بعضی از پست های سایت ما به صورت متغیر هستند مثلا در کنار تخت پاتختی و میز ارایش و... هم برای فروش هست که به هر کدام یک قیمت دادیم و هیچ مشکلی نیست

تنها مشکل ما تو نمایش سایته که دو قیمت متفاوت نمایش داده میشه و مشتری یکم دگرگون میشه

من میخوام که به این شکل نشون بده

 10000 تومان - 9000 تومان

بگه قیمت تخت 10000 تومان بوده اما ما میدیم 9000 :D

ولی چون متغیره محصولمون قیمت دو تا محصول مختلف رو نشون میده

You must be registered for see images attach


 

Mohammad

مدیر انجمن
پرسنل مدیریت
برای نمایش تنها یک قیمت

کد زیر رو درون functions.php قالبتون وارد کنید (در انتهای کد ها)

کد:
add_filter('woocommerce_variable_sale_price_html', 'shop_variable_product_price', 10, 2);
add_filter('woocommerce_variable_price_html','shop_variable_product_price', 10, 2 );
function shop_variable_product_price( $price, $product ){
    $variation_min_reg_price = $product->get_variation_regular_price('min', true);
    $variation_min_sale_price = $product->get_variation_sale_price('min', true);
    if ( $product->is_on_sale() && !empty($variation_min_sale_price)){
        if ( !empty($variation_min_sale_price) )
            $price = '<del class="strike">' .  woocommerce_price($variation_min_reg_price) . '</del>
        <ins class="highlight">' .  woocommerce_price($variation_min_sale_price) . '</ins>';
    } else {
        if(!empty($variation_min_reg_price))
            $price = '<ins class="highlight">'.woocommerce_price( $variation_min_reg_price ).'</ins>';
        else
            $price = '<ins class="highlight">'.woocommerce_price( $product->regular_price ).'</ins>';
    }
    return $price;
}
 

ma30ud

تازه وارد
کد درست بود و خیلی خوب کار میکرد ولی به نظرم پایین ترین نرخ قیمت یک محصول رو توی صفحه اصلی نشون میده

من میخوام که فقط قیمت تخت رو نشون بده

شما اگه بتونی با یکم تغییر در کد بالا یه کاری کنی که بیشترین نرخ قیمت محصول رو نشون بده عالی میشه

ممنون

 

ma30ud

تازه وارد
سلام

خودم با یکم دست کاری تو کد تونستم کارمو راه بندازم دوستانی هم که مشکل من و دارن میتونن از کد زیر تو functions.php قالبشون اضافه کنن و کارشون راه بیوفته :) :53:

کد:
add_filter('woocommerce_variable_sale_price_html', 'shop_variable_product_price', 10, 2);
add_filter('woocommerce_variable_price_html','shop_variable_product_price', 10, 2 );
function shop_variable_product_price( $price, $product ){
    $variation_max_reg_price = $product->get_variation_regular_price('max', true);
    $variation_max_sale_price = $product->get_variation_sale_price('max', true);
    if ( $product->is_on_sale() && !empty($variation_max_sale_price)){
        if ( !empty($variation_max_sale_price) )
            $price = '<del class="strike">' .  woocommerce_price($variation_max_reg_price) . '</del>
        <ins class="highlight">' .  woocommerce_price($variation_max_sale_price) . '</ins>';
    } else {
        if(!empty($variation_max_reg_price))
            $price = '<ins class="highlight">'.woocommerce_price( $variation_max_reg_price ).'</ins>';
        else
            $price = '<ins class="highlight">'.woocommerce_price( $product->regular_price ).'</ins>';
    }
    return $price;
}
 
آخرین ویرایش توسط مدیر:
بالا