programing

WooCommerce 프론트엔드에서 주문항목 메타 숨기기(관리 아님)

closeapi 2023. 9. 28. 08:24
반응형

WooCommerce 프론트엔드에서 주문항목 메타 숨기기(관리 아님)

고객이 보고 싶지 않은 몇 가지 주문 항목 메타 세부 정보가 있습니다(계정 정보 아래 주문 보기 페이지).관리자(계속 보고 싶은 위치)에서 이 데이터를 제거할 필터를 찾았지만 FRONT END(숨겨야 하는 위치)에서 제거할 유사한 필터를 찾을 수 없습니다.

백엔드 관리자에서 제거하는 코드는 다음과 같습니다.

add_filter( 'woocommerce_hidden_order_itemmeta', 'add_hidden_order_items' );
function add_hidden_order_items( $order_items ) {
    $order_items[] = 'paid_already';
    $order_items[] = 'variation_sku';
    // and so on...
    return $order_items;
}

밑줄 접두사로 값을 저장하면 표시되지 않고 저장됩니다.이와 같습니다.

$item->add_meta_data('_hidden_field', '123', true);
//remove order item meta key
add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'mobilefolk_order_item_get_formatted_meta_data', 10, 1 );

function mobilefolk_order_item_get_formatted_meta_data($formatted_meta){
    $temp_metas = [];
    foreach($formatted_meta as $key => $meta) {
        if ( isset( $meta->key ) && ! in_array( $meta->key, [
                'lyric_id',
                'lyric_song_title',
                'lyric_artist_name'
            ] ) ) {
            $temp_metas[ $key ] = $meta;
        }
    }
    return $temp_metas;
}

일부 항목 메타를 프론트 엔드 오더 뷰에서 숨기려면 재정의해야 합니다.
order-details-item.phpwocommerce 템플릿 파일.

다음을 추천합니다.테마 방법을 통해 우커머스 템플릿을 재정의하고 템플릿을 활성 테마(또는 하위 테마 더 나은 테마)에 복사하고 이름을 "우커머스"로 변경합니다.활성화된 테마 안에 있는 우커머스 폴더에 복사하면order-details-item.php인에order하위 폴더

의 36번째 줄에order-details-item.php다음을 찾을 수 있습니다.

            $order->display_item_meta( $item );
            $order->display_item_downloads( $item );

다음과 같은 조건을 추가하여 변경할 수 있습니다.

            if ( $item != 'paid_already' || $item != 'variation_sku') {
                $order->display_item_meta( $item );
                $order->display_item_downloads( $item );
            }

저는 이 조건의 정확성을 확신할 수 없어서 테스트할 수 없습니다.당신은 그것을 약간 바꾸어야 할지도 모릅니다.

참고로 기능 display_item_meta()는 다음과 같은 방식으로 작동합니다.

/**
 * Display meta data belonging to an item.
 * @param  array $item
 */
public function display_item_meta( $item ) {
    $product   = $this->get_product_from_item( $item );
    $item_meta = new WC_Order_Item_Meta( $item, $product );
    $item_meta->display();
}

참조:

meta_key를 주문하기 전에 " _ "를 사용합니다.

음, 생각보다 훨씬 쉬워졌고, 템플릿은 이미 내 아이템 메타의 이름을 가진 클래스를 제공하고 있어서, 나는 그냥 css에 그렇게 숨겼습니다.

.order_details .variation-variation_sku, .order_details .variation-paid_already {
    display: none !important;
}

이러한 아이템 메타가 출력되는 것을 방지하는 방법을 알고 싶지만, 이것을 해결책으로 삼아 살 수 있습니다.

아이템 메타데이터를 다루면서, 저는 단지 CSS를 사용하여 카트에서 아이템 메타데이터를 숨기고 있습니다.

.wc-item-meta {display:none;}

언급URL : https://stackoverflow.com/questions/37596481/woocommerce-hide-order-item-meta-from-front-end-not-admin

반응형