2016-06-27 4 views
5

와 장바구니 가격 우선 우리는 함께 제품의 무리가 다음 중 하나WooCommerce : 텍스트

  • 우리는 내장 후크 만에 그들을 구매할 만든
  • 제로 가격

가격 정보 없음 장바구니에는 체크 아웃 중에 여전히 0 price으로 표시됩니다.

& "특별 주문"또는 기타 텍스트를 표시하려면 카트를 사용하고 싶지만 WooCommerce는 텍스트 기반 가격을 무효화하는 것으로 보입니다.

이 시도 : WooCommerce: Add product to cart with price override?

은 위의 숫자 오버라이드 잘 작동하지만 텍스트로 시도 할 때 0 price를 표시 다시 그것을 기본값을 재정의합니다.

왜? 이 제품은 주문 생산 형이며 매장 관리자는 고객/공급 업체와 통화 한 후 가격을 업데이트합니다.

답변

4

카트의 가격과 부분합을 표시하는 문자열을 필터링해야합니다. 언급 한 링크에서 실제 가격을 변경하는 방법에 대해 논의했습니다. 귀하의 경우 실제 가격을 나중에 설정할 때까지 $ 0입니다. 이 카트가 너무 합계를 위해 아마 필터입니다, 그러나 이것은 시작해야한다 : 사용자 정의로 설정 한

물론
add_filter('woocommerce_cart_item_price', 'so_38057349_cart_item_price', 10, 3); 
function so_38057349_cart_item_price($price, $cart_item, $cart_item_key) { 

    if ($cart_item[ 'data' ]->price == 0) { 
     $price = __('Special Order', 'yourtheme'); 
    } 

    return $price; 
} 


add_filter('woocommerce_cart_item_subtotal', 'so_38057349_cart_item_subtotal', 10, 3); 
function so_38057349_cart_item_subtotal($subtotal, $cart_item, $cart_item_key) { 

    if ($cart_item[ 'data' ]->price == 0) { 
     $subtotal = __('To be determined', 'yourtheme'); 
    } 

    return $subtotal; 
} 


add_filter('woocommerce_order_formatted_line_subtotal', 'so_38057349_order_item_subtotal', 10, 3); 
function so_38057349_order_item_subtotal($subtotal, $item, $order) { 

    if (isset($item[ 'line_subtotal' ]) && $item[ 'line_subtotal' ] == 0) { 
     $subtotal = __('To be determined', 'yourtheme'); 
    } 

    return $subtotal; 
} 

,이 또한 0 가격으로 모든 제품에 적용됩니다 아마뿐만 아니라 사람 내장되어 있으므로 여기서 제공 한 것보다 더 많은 조건부 논리가 필요할 수도 있습니다.

귀하의 의견을 따르십시오 .... woocommerce_order_amount_total은 총 숫자이며 표시된 html이 아닙니다. cart-totals.php 템플릿에서 호출되는 함수를 볼 수 있습니다.

function so_38057349_woocommerce_cart_subtotal($cart_subtotal, $compound, $cart) { 
    if($cart->subtotal == 0){ 
     $cart_subtotal = __('Order subtotal to be determined', 'yourtheme'); 
    } 
    return $cart_subtotal; 
}; 
add_filter('woocommerce_cart_subtotal', 'so_38057349_woocommerce_cart_subtotal', 10, 3); 


// define the woocommerce_order_amount_total callback 
function so_38057349_woocommerce_order_amount_total($order_total) { 
    if(WC()->cart->get_total() == 0){ 
     $order_total = __('Order total to be determined', 'yourtheme'); 
    } 
    return $order_total; 
}; 
add_filter('woocommerce_cart_totals_order_total_html', 'so_38057349_woocommerce_order_amount_total'); 

업데이트 스크린 샷 : 헬가의 대답에 확대 cart

+0

헬가 정말 고마워요. 정확하게 필요한 것입니다. 귀하의 사례를 확대하여 장바구니 및 결제 페이지도 보호합니다! – radug

+0

내 편집을 확인하십시오. 질문의 오류와 유사하게 'woocommerce_order_amount_total'는 HTML 문자열이 아닙니다. – helgatheviking

1

, 여기에 가격이 너무 카트 페이지, 체크 아웃 페이지와 주문 확인 이메일에 '결정하는'에 변경 전체 코드입니다. 텍스트는 사람들이 각 필터가가는 곳을 파악할 수 있도록 다양하게 유지되었습니다.

add_filter('woocommerce_cart_item_price', 'filter_cart_item_price', 10, 3); 
function filter_cart_item_price($price, $cart_item, $cart_item_key) { 
    if ($cart_item[ 'data' ]->price == 0) { 
     $price = __('Special Order', 'yourtheme'); 
    } 
    return $price; 
} 

add_filter('woocommerce_cart_item_subtotal', 'filter_cart_item_subtotal', 10, 3); 
function filter_cart_item_subtotal($subtotal, $cart_item, $cart_item_key) { 
    if ($cart_item[ 'data' ]->price == 0) { 
     $subtotal = __('To be determined', 'yourtheme'); 
    } 
    return $subtotal; 
} 

add_filter('woocommerce_cart_subtotal', 'filter_woocommerce_cart_subtotal', 10, 3); 
function filter_woocommerce_cart_subtotal($cart_subtotal, $compound, $instance) { 
    $cart_subtotal = __('To be determined 4', 'yourtheme'); 
    return $cart_subtotal; 
}; 


add_filter('woocommerce_order_formatted_line_subtotal', 'filter_order_item_subtotal', 10, 3); 
function filter_order_item_subtotal($subtotal, $item, $order) { 
    if (isset($item[ 'line_subtotal' ]) && $item[ 'line_subtotal' ] == 0) { 
     $subtotal = __('To be determined 2', 'yourtheme'); 
    } 
    return $subtotal; 
} 

add_filter('woocommerce_order_subtotal_to_display', 'filter_woocommerce_order_subtotal_to_display', 10, 3); 
function filter_woocommerce_order_subtotal_to_display($subtotal, $compound, $instance) { 
     $subtotal = __('To be determined 6', 'yourtheme'); 
    return $subtotal; 
}; 

add_filter('woocommerce_get_formatted_order_total', 'filter_woocommerce_get_formatted_order_total', 10, 2); 
function filter_woocommerce_get_formatted_order_total($formatted_total, $instance) { 
     $formatted_total = __('To be determined 8', 'yourtheme'); 
    return $formatted_total; 
};