1
어떻게 현재 카테고리에 관련 제품의 최소 가격과 최대 가격을 표시 할 수 있습니까?Woocommerce 제품 범주 아카이브의 최소 가격 및 최대 가격 표시
그냥 2 개의 숫자 - 가장 저렴한 제품 카테고리의 가격과 가장 비싼 제품 카테고리의 가격.
어떻게 현재 카테고리에 관련 제품의 최소 가격과 최대 가격을 표시 할 수 있습니까?Woocommerce 제품 범주 아카이브의 최소 가격 및 최대 가격 표시
그냥 2 개의 숫자 - 가장 저렴한 제품 카테고리의 가격과 가장 비싼 제품 카테고리의 가격.
다음은 single_term_title
Wordpress 관련 필터 후크에 걸린 사용자 지정 기능의 예입니다. 그러면 제품 가격대가 범주 제목에 추가됩니다.
현재 제품 카테고리의 모든 제품 가격을 SQL 쿼리에서 가져옵니다. 그런 다음 제목 뒤에 관련 제품의 가격 범위를 표시합니다.
add_filter('single_term_title', 'product_category_term_title', 10, 1);
function product_category_term_title($term_title){
// Only for product category archive pages
if(! (is_tax() && is_product_category()))
return $term_title;
// Get the current product category term object
$term = get_queried_object();
global $wpdb;
# Get ALL related products prices related to a specific product category
$results = $wpdb->get_col("
SELECT pm.meta_value
FROM {$wpdb->prefix}term_relationships as tr
INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN {$wpdb->prefix}terms as t ON tr.term_taxonomy_id = t.term_id
INNER JOIN {$wpdb->prefix}postmeta as pm ON tr.object_id = pm.post_id
WHERE tt.taxonomy LIKE 'product_cat'
AND t.term_id = {$term->term_id}
AND pm.meta_key = '_price'
");
// Sorting prices numerically
sort($results, SORT_NUMERIC);
// Get the min and max prices
$min = current($results);
$max = end($results);
// Format the price range after the title
$price_range = sprintf(__(' <small>(from %1$s to %2$s)</small>', 'woocommerce'), wc_price($min), wc_price($max));
return $term_title . $price_range;
}
테스트를 거쳐 작동합니다. 너는 무언가를 얻을 것이다 :