[英]WooCommerce query all products with a purchase note
我正在努力獲得所有有購買記錄的產品,包括簡單產品和可變產品。
WC_Product_Query
似乎無法做到這一點,因為它沒有提供購買票據的方法。 因為它不是 meta_data 而是一個實際的產品字段,所以我不知道該怎么做。
有沒有人可以查詢上述內容的方向?
$products = wc_get_products(array(
'post_status' => array('publish', 'pending', 'draft', 'future', 'private'),
'limit' => 1000,
'orderby' => 'id',
'order' => 'asc',
'_purchase_note' => true,
));
function handle_custom_query_var( $query, $query_vars ) {
if ( ! empty( $query_vars['_purchase_note'] ) ) {
$query['meta_query'][] = array(
'key' => '_purchase_note',
'compare' => '!=',
'value' => ''
);
}
return $query;
}
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', 'handle_custom_query_var', 10, 2 );
在此處查看更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.