Woocommerce可变产品价格前缀

问题描述 投票:1回答:1

目前我使用这个代码/插件显示的前缀,而最低价店:

function show_only_lowest_prices_in_woocommerce_variable_products_load_plugin_textdomain() {
    load_plugin_textdomain( 'show-only-lowest-prices-in-woocommerce-variable-products', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'show_only_lowest_prices_in_woocommerce_variable_products_load_plugin_textdomain' );
//Simple products
function wc_wc20_variation_price_format( $price, $product ) {
    // Main prices
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'От %1$s', 'show-only-lowest-prices-in-woocommerce-variable-products' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    // Sale price
    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
    sort( $prices );
    $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'От %1$s', 'show-only-lowest-prices-in-woocommerce-variable-products' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    if ( $price !== $saleprice ) {
        $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
    }
    return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
//Grouped products
// Show product prices in WooCommerce 2.0 format
add_filter( 'woocommerce_grouped_price_html', 'wc_wc20_grouped_price_format', 10, 2 );
function wc_wc20_grouped_price_format( $price, $product ) {
	$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
	$child_prices     = array();
	foreach ( $product->get_children() as $child_id ) {
		$child_prices[] = get_post_meta( $child_id, '_price', true );
	}
	$child_prices     = array_unique( $child_prices );
	$get_price_method = 'get_price_' . $tax_display_mode . 'uding_tax';
	if ( ! empty( $child_prices ) ) {
		$min_price = min( $child_prices );
		$max_price = max( $child_prices );
	} else {
		$min_price = '';
		$max_price = '';
	}
	if ( $min_price == $max_price ) {
		$display_price = wc_price( $product->$get_price_method( 1, $min_price ) );
	} else {
		$from          = wc_price( $product->$get_price_method( 1, $min_price ) );
		$display_price = sprintf( __( 'От %1$s', 'show-only-lowest-prices-in-woocommerce-variable-products' ), $from );
	}
	return $display_price;
}

但我需要改变它,像这样的前缀,以显示两者价格(最小值和最大值)

从10到25 LV

我试图编辑,但在此代码我不能得到最大的价格展现给放前缀。

wordpress variables woocommerce price
1个回答
1
投票

尽量使用专用钩,下面较短功能:

add_filter( 'woocommerce_format_price_range', 'format_price_range_prefix', 20, 3 );
function format_price_range_prefix( $price, $from, $to ) {
    $price = sprintf( _x( 'From %1$s to %2$s %3$s', 'Price range: from-to', 'woocommerce' ), is_numeric( $from ) ? wc_price( $from ) : $from, is_numeric( $to ) ?  wc_price( $to ) : $to, __('lv', 'woocommerce') );
    return $price;
}

代码放在您的活动子主题的function.php文件(或活动主题)。测试和工程。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.