2017-02-21 4 views
0

나는 판매중인 제품 만 판매되는 판매 페이지에서 사용해야하는 본사의 표준 PHP 페이지 템플릿을 만들었습니다. PHP를 통해 판매중인 4 개의 무작위 제품을 어떻게 표시 할 수 있습니까?WooCommerce : 루프 밖에서 판매 제품을 표시하는 방법

WooCommerce에는 판매 제품을 표시하는 짧은 코드가 있지만 do_shortcode 함수를 통해 호출하면 작동하지 않습니다.

답변

1

독자적인 쿼리를 사용할 수 있습니다.

$args = array(
'post_type' => 'product', 
'showposts' => 4, 
'orderby' => 'rand', 
'meta_query' => array(
    'relation' => 'OR', 
    array(// Simple products type 
     'key'  => '_sale_price', 
     'value' => 0, 
     'compare' => '>', 
     'type' => 'numeric' 
    ), 
    array(// Variable products type 
     'key'  => '_min_variation_sale_price', 
     'value' => 0, 
     'compare' => '>', 
     'type' => 'numeric' 
    ) 
) 
); 

$sale_products = new WP_Query($args); 

왜 짧은 코드가 작동하지 않을지 잘 모름

echo do_shortcode('[sale_products columns="4" per_page="4"]'); 
관련 문제