WooCommerce:카트 품목에 대한 제품 변형 설명도 표시
내 카트에 내 제품 변형 설명을 표시하려고 합니다.템플릿에 다음 코드를 삽입해 보았습니다.
if ( $_product->is_type( 'variation' ) ) {echo $_product->get_variation_description();}
이 매뉴얼에 따라 https://docs.woocommerce.com/document/template-structure/ 를 참조해 주세요.
근데 아직도 안 보여.
내가 여기서 뭘 잘못하고 있는지 모르겠어.
누구 도와줄 사람 있어?
WooCommerce 버전 3 이후 업데이트됨
WooCommerce 3 이후, 현재는 폐지되어 에 의해 대체되고 있습니다. WC_Product
방법.
제품 항목 변동 설명(변동 제품 유형 조건 필터링)을 얻으려면 대신 다음과 같은 후크 함수를 사용할 수 있습니다.
// Cart page (and mini cart)
add_filter( 'woocommerce_cart_item_name', 'cart_item_product_description', 20, 3);
function cart_item_product_description( $item_name, $cart_item, $cart_item_key ) {
if ( ! is_checkout() ) {
if( $cart_item['variation_id'] > 0 ) {
$description = $cart_item['data']->get_description(); // variation description
} else {
$description = $cart_item['data']->get_short_description(); // product short description (for others)
}
if ( ! empty($description) ) {
return $item_name . '<br><div class="description">
<strong>' . __( 'Description', 'woocommerce' ) . '</strong>: '. $description . '
</div>';
}
}
return $item_name;
}
// Checkout page
add_filter( 'woocommerce_checkout_cart_item_quantity', 'cart_item_checkout_product_description', 20, 3);
function cart_item_checkout_product_description( $item_quantity, $cart_item, $cart_item_key ) {
if( $cart_item['variation_id'] > 0 ) {
$description = $cart_item['data']->get_description(); // variation description
} else {
$description = $cart_item['data']->get_short_description(); // product short description (for others)
}
if ( ! empty($description) ) {
return $item_quantity . '<br><div class="description">
<strong>' . __( 'Description', 'woocommerce' ) . '</strong>: '. $description . '
</div>';
}
return $item_quantity;
}
이제 제목과 변동 속성 값 사이에 설명이 표시됩니다(있는 경우).
코드는 기능합니다.php 파일(또는 활성 테마)입니다(또는 활성 테마)을 입력합니다.테스트 및 동작.
이것은 WC 3.0에서 동작합니다.
add_filter( 'woocommerce_cart_item_name', 'cart_variation_description', 20, 3);
function cart_variation_description( $title, $cart_item, $cart_item_key ) {
$item = $cart_item['data'];
if(!empty($item) && $item->is_type( 'variation' ) ) {
return $item->get_name();
} else
return $title;
}
글로벌 변수를 통해 얻을 수 있습니다.$woocommerce
또,
global $woocommerce;
$cart_data = $woocommerce->cart->get_cart();
foreach ($cart_data as $value) {
$_product = $value['data'];
if( $_product->is_type( 'variation' ) ){
echo $_product->id . '<br>';
}
}
이미 확인했습니다.
언급URL : https://stackoverflow.com/questions/39045038/woocommerce-display-also-product-variation-description-on-cart-items
'programing' 카테고리의 다른 글
Python의 JSON 어레이를 통한 루프 (0) | 2023.03.15 |
---|---|
명령줄을 사용하여 JSON 개체의 항목을 계산하려면 어떻게 해야 합니까? (0) | 2023.03.15 |
React - 하위 DOM 요소에서 React 구성 요소를 가져오시겠습니까? (0) | 2023.03.15 |
리액트 사용각도가 있는 JSJS (0) | 2023.03.15 |
WooCommerce는 속성 쿼리를 통해 제품을 가져옵니다. (0) | 2023.03.15 |