簡體   English   中英

隱藏類別頁面上的價格范圍變化 Woocommerce

[英]Hide price range variation on category pages Woocommerce

我正在使用代碼將實時變化價格移動到產品頁面的頂部,並刪除產品頁面和類別頁面上的價格范圍,以僅顯示最低價格值。

還需要顯示價格稅后綴“IVA inc”。 這個后綴是在 woocommerce 配置上設置的。

除了預售價格未顯示在類別頁面上之外,它完美運行

我不是編程專家,我正在努力讓它發揮作用。

除此之外,是否可以優化代碼?

//Move Variations price above variations to have the same template even if variations prices are the same
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_single_variation', 10 ); 

//Remove Price Range
add_filter( 'woocommerce_variable_sale_price_html', 'detect_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'detect_variation_price_format', 10, 2 );

function detect_variation_price_format( $price, $product ) {

// Main Price

$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
if ($prices[0] !== $prices[1] && is_product()) {
    $price = $prices[0] !== $prices[1] ? sprintf( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
}
return $price;
}



add_filter( 'woocommerce_variable_price_html', 'custom_min_max_variable_price_html', 10, 2 );
function custom_min_max_variable_price_html( $price, $product ) {
    $prices = $product->get_variation_prices( true );
    $min_price = current( $prices['price'] );

    $min_price_html = wc_price( $min_price ) . $product->get_price_suffix();
    $price = sprintf( __( '%1$s', 'woocommerce' ), $min_price_html );

    return $price;
}

優惠銷售前的價格未顯示在類別頁面上

在此處輸入圖片說明

產品頁面工作正常

在此處輸入圖片說明

要隱藏存檔/商店頁面上的價格范圍,您可以覆蓋該功能

woocommerce_template_loop_price可插拔。 此函數位於 /includes/wc-template-functions.php

function woocommerce_template_loop_price() {
    // Just do nothing
    return;
}

但是,這將刪除商店/存檔頁面上顯示的所有價格。

編輯:在評論中更新問題后,這顯示了如何在商店/存檔頁面上僅顯示可變產品的最小變化價格。

function woocommerce_template_loop_price() {
    global $product;
    if ($product->get_type() == 'variable'){
        echo '<span class="price">' . wc_price($product->get_variation_regular_price('min')) . '</span>';
    } else {
        wc_get_template( 'loop/price.php' );
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM