更改 WPBakery Woocommerce 产品循环简码以最后订购缺货产品或隐藏
Change WPBakery Woocommerce product loop shortcode to order out of stock products at last or hide
我在我的站点中使用自定义商店页面。我在那里使用 WPBakery(以前的 Visual Composer)的 "Product Loop" 组件。
我想更改 "Recent" 订单以使 "Out of Stock" 产品在这种情况下不显示,我尝试将
'stock_status' => 'instock',
在下面的代码中,但它不起作用。
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
switch ($display) {
case 'recent':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'stock_status' => 'instock',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'orderby' => 'date',
'order' => 'desc',
'paged' => $paged,
'meta_query' => WC()->query->get_meta_query(),
);
break;
不管有没有线结果都是一样的
另一种情况:
我想更改 "Top Rated" 选项以使 "Out of Stock" 产品出现在产品循环的末尾。
我有以下代码:
case 'top_rated':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'order' => $order,
'paged' => $paged,
'meta_key' => '_wc_average_rating',
'orderby' => 'meta_value_num',
'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(),
);
break;
我需要使用带有 2 个参数的查询,最高评分和 stock_status。如何在上面的代码中创建查询?
我的环境:
主题木星版本 6.1.1
WP面包店 5.4.5.1
WooCommerce 版本 3.3.4
WordPress 4.9.4
抱歉,我在 PHP 方面的知识是新手...
对于 'recent' 案例:
//RAS
//creates a variable with the standard meta query of woocommerce
$meta_query = WC()->query->get_meta_query();
/*adds custom metakey to variable above with argument to display all that have the field
'_stock_status' with value other than outofstock
*/
$meta_query[] = array(
'relation' => 'AND',
array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '!='
),
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'orderby' => 'date',
'order' => 'desc',
'paged' => $paged,
'meta_query' => $meta_query,//use variable created as an argument
);
break;
对于第二种情况。
案例 'top_rated':
//RAS
//cria uma variável com a meta query padrao do woocommerce
$meta_query = WC()->query->get_meta_query();
/*cria instancias para as 2 metakeys(array) para utilizar como argumento no orderby, e adiciona a variável acima.*/
$meta_query = array(
'relation' => 'AND',
'rating' => array('key' => '_wc_average_rating','compare' => 'EXISTS',),
'stockstatus' => array('key' => '_stock_status','compare' => 'EXISTS',),
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
//'order' => $order,
'paged' => $paged,
//'meta_key' => '_wc_average_rating',
//'orderby' => 'meta_value_num',
'meta_query' => $meta_query,//usa a variavel criada como argumento
'tax_query' => WC()->query->get_tax_query(),
'orderby' => array('rating'=>'DESC','stockstatus'=>'ASC',),//usa as instancias criadas como argumento para orderby.
);
break;
我在我的站点中使用自定义商店页面。我在那里使用 WPBakery(以前的 Visual Composer)的 "Product Loop" 组件。
我想更改 "Recent" 订单以使 "Out of Stock" 产品在这种情况下不显示,我尝试将
'stock_status' => 'instock',
在下面的代码中,但它不起作用。
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
switch ($display) {
case 'recent':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'stock_status' => 'instock',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'orderby' => 'date',
'order' => 'desc',
'paged' => $paged,
'meta_query' => WC()->query->get_meta_query(),
);
break;
不管有没有线结果都是一样的
另一种情况:
我想更改 "Top Rated" 选项以使 "Out of Stock" 产品出现在产品循环的末尾。 我有以下代码:
case 'top_rated':
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'order' => $order,
'paged' => $paged,
'meta_key' => '_wc_average_rating',
'orderby' => 'meta_value_num',
'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(),
);
break;
我需要使用带有 2 个参数的查询,最高评分和 stock_status。如何在上面的代码中创建查询?
我的环境:
主题木星版本 6.1.1
WP面包店 5.4.5.1
WooCommerce 版本 3.3.4
WordPress 4.9.4
抱歉,我在 PHP 方面的知识是新手...
对于 'recent' 案例:
//RAS
//creates a variable with the standard meta query of woocommerce
$meta_query = WC()->query->get_meta_query();
/*adds custom metakey to variable above with argument to display all that have the field
'_stock_status' with value other than outofstock
*/
$meta_query[] = array(
'relation' => 'AND',
array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '!='
),
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
'orderby' => 'date',
'order' => 'desc',
'paged' => $paged,
'meta_query' => $meta_query,//use variable created as an argument
);
break;
对于第二种情况。 案例 'top_rated':
//RAS
//cria uma variável com a meta query padrao do woocommerce
$meta_query = WC()->query->get_meta_query();
/*cria instancias para as 2 metakeys(array) para utilizar como argumento no orderby, e adiciona a variável acima.*/
$meta_query = array(
'relation' => 'AND',
'rating' => array('key' => '_wc_average_rating','compare' => 'EXISTS',),
'stockstatus' => array('key' => '_stock_status','compare' => 'EXISTS',),
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $count,
//'order' => $order,
'paged' => $paged,
//'meta_key' => '_wc_average_rating',
//'orderby' => 'meta_value_num',
'meta_query' => $meta_query,//usa a variavel criada como argumento
'tax_query' => WC()->query->get_tax_query(),
'orderby' => array('rating'=>'DESC','stockstatus'=>'ASC',),//usa as instancias criadas como argumento para orderby.
);
break;