추천 상품은 GB 쿼리 블록에서 바로 지원하지 않습니다.
방법 1. 사이트 워커
- ‘설정 > 사이트 워커’의 ‘GenerateBlocks X 우커머스’ 탭으로 이동합니다.
- ‘쿼리 블록’의 ‘추천 상품 지원’을 활성화하고, ‘변경사항 저장’을 클릭합니다.
- 쿼리 블록으로 상품 목록을 만듭니다.
- 쿼리 블록 설정의 ‘고급’의 ‘Additional CSS class(es)’에 ‘query--featured-products’를 입력합니다.
방법 2. 코드
1) 쿼리 코드 입력
아래 PHP 코드를 사용해 추천 상품 목록 쿼리를 만듭니다.
add_filter( 'generateblocks_query_wp_query_args', 'custom_gb2_featured_products_query', 10, 2 );
if ( ! function_exists( 'custom_gb2_featured_products_query' ) ) {
function custom_gb2_featured_products_query( $query_args, $attributes ) {
// 1. GB 2.0+ 쿼리 블록 패널에 지정한 클래스명 검사
if ( empty( $attributes['className'] ) || strpos( $attributes['className'], 'query--featured-products' ) === false ) {
return $query_args;
}
// 2. tax_query 배열이 없으면 초기화
if ( ! isset( $query_args['tax_query'] ) || ! is_array( $query_args['tax_query'] ) ) {
$query_args['tax_query'] = array();
}
// 3. 우커머스 별표(Featured) 택소노미 필터 조건 추가
// terms 는 반드시 배열이어야 한다. GB Pro 의 current_post_terms()
// (generateblocks-pro/includes/extend/query/class-query.php:371) 가
// in_array( 'current', $tax['terms'], true ) 를 호출하므로
// 문자열을 넣으면 TypeError 로 사이트가 500 이 된다.
$query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => array( 'featured' ),
'operator' => 'IN',
);
return $query_args;
}
}Code language: PHP (php)2) 쿼리 블록 만들기
GB 쿼리 블록으로 상품 목록을 출력합니다.
- 쿼리 블록으로 상품 목록을 만듭니다.
- 쿼리 블록 설정의 ‘고급’의 ‘Additional CSS class(es)’에 ‘query--featured-products’를 입력합니다.