FacetWP에서 데이터 소스 중 우커머스 관련 소스 중 판매자 소스는 지원되지 않습니다.
글 > 글 작성자 를 통해서도 할수 있지만 이경우는 모든 Post_type 에 대해서 인덱싱이 됩니다.
이로 인해 “product_variation” 역시 인덱싱이 되며, “Product” 타입과 “product_variation” 의 작성자가 다른경우가 존재하기 때문에 “Product” 타입의 작성자만 인덱싱이 필요할때가 있습니다.
add_filter("facetwp_facet_sources", function($sources){
$sources['woocommerce']['choices']['woo/vender'] = __( '판매자' );
return $sources;
}, 20);
Code language: PHP (php)
해당 코드로 Facet 의 데이터 소스에 ‘판매자’ 라는 소스 를 추가합니다.
add_filter("facetwp_indexer_post_facet", function($return, $params){
$facet = $params['facet'];
$defaults = $params['defaults'];
$post_id = (int) $defaults['post_id'];
$post_type = get_post_type( $post_id );
// Index out of stock products?
$index_all = ( 'yes' === FWP()->helper->get_setting( 'wc_index_all', 'no' ) );
$index_all = apply_filters( 'facetwp_index_all_products', $index_all );
if ( 'product' == $post_type || 'product_variation' == $post_type ) {
$product = wc_get_product( $post_id );
if ( ! $product || ( ! $index_all && ! $product->is_in_stock() ) ) {
return true; // skip
}
}
// Default handling
if ( 'product' != $post_type || empty( $facet['source'] ) ) {
return $return;
}
if ( 'woo/vender' === $facet['source'] ) {
$post = get_post( $post_id );
$value = $post->post_author;
cym_debug("post_id =" .$post_id . " / author = ". $value);
// $value = $product->post_author;
$user = get_user_by( 'id', $value );
$display_value = ( $user instanceof WP_User ) ? $user->display_name : $value;
$defaults['facet_value'] = $value;
$defaults['facet_display_value'] = $display_value;
FWP()->indexer->index_row( $defaults );
return true;
}
return $return;
}, 20 , 2);
Code language: PHP (php)
해당 코드로 Product 타입의 판매자를 인덱싱 할수 있습니다.