2017-12-08 2 views
1

가변 제품에 다른 가격의 변형이있는 경우 WooCommerce에서 2 가지 금액의 가격 범위가 표시됩니다 (예 : 89.00 - 109.00).가변 제품 가격 범위를 WooCommerce의 "보낸 사람"및 최저 가격으로 대체

나는 "보낸 사람 :"만 표시하고 최저 가격은 From: 89.00 (최대 가격 제외)과 같이 변경하고 싶습니다.
("Fra :"는 내 언어로, 이는 분명히 설명합니다.) 이 코드는 작동하지 않습니다

// Main Price 
$prices = array($product->get_variation_price('min', true), $product->get_variation_price('max', true)); 
$price = $prices[0] !== $prices[1] ? sprintf(__('Fra: %1$s', 'woocommerce'), 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(__('Fra: %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]); 

if ($price !== $saleprice) { 
$price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>'; 
} 
return $price; 
} 

: 여기

내가 시도 코드입니다. 추가 할 때마다 아무 일도 일어나지 않습니다.

대신 "최저 가격 :"+ 최소 가격을 얻으려면 무엇을 변경해야합니까?

답변

1

코드는 여기에

그것은 당신의 변수 제품에 대한 작동하는지 확인하는 올바른 방법입니다 ... 후크 및 누락 된 함수로 조금 불완전 :

add_filter('woocommerce_get_price_html', 'change_variable_products_price_display', 10, 2); 
function change_variable_products_price_display($price, $product) { 

    // Only for variable products type 
    if(! $product->is_type('variable')) return $price; 

    $prices = $product->get_variation_prices(true); 

    if (empty($prices['price'])) 
     return apply_filters('woocommerce_variable_empty_price_html', '', $product); 

    $min_price = current($prices['price']); 
    $max_price = end($prices['price']); 
    $prefix_html = '<span class="price-prefix">' . __('Fra: ') . '</span>'; 

    $prefix = $min_price !== $max_price ? $prefix_html : ''; // HERE the prefix 

    return apply_filters('woocommerce_variable_price_html', $prefix . wc_price($min_price) . $product->get_price_suffix(), $product); 
} 

코드에 간다 활성 자식 테마 (또는 테마) 또는 모든 플러그인 파일의 function.php 파일.

테스트를 거쳐 작동합니다.

+0

아하는 아주 좋습니다. 그것은 정말로 효과가있었습니다, 놀랍습니다. 나는 당신을 문제 해결로 표시 할 것입니다. 그러나 한 가지 질문은 "Fra"(텍스트에서) 스타일을 지정할 수 있다는 것입니다. 그것은 내 경우에 실제 가격보다 훨씬 작고 회색으로 퇴색 한 색입니다. 그것 자체에 의해 ID를 가지고있는 것 같아서 CSS로 할 수 없다. – eMikkelsen

+0

물론, 이미 그렇게하지 못해서 너무 유감입니다. 이로써 표시됩니다. 고맙습니다 – eMikkelsen

관련 문제