简体   繁体   English

WooCommerce 使用购买说明查询所有产品

[英]WooCommerce query all products with a purchase note

I am struggling to get all products that have a purchase note, both simple products and variable products.我正在努力获得所有有购买记录的产品,包括简单产品和可变产品。

WC_Product_Query doesn't seem to be able to do that, as that does not provide a method for purchase notes. WC_Product_Query似乎无法做到这一点,因为它没有提供购买票据的方法。 As it's not meta_data but an actual product field I'm don't see how to do this.因为它不是 meta_data 而是一个实际的产品字段,所以我不知道该怎么做。

Has anyone a direction in which I would be able to query the above?有没有人可以查询上述内容的方向?

$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 );

See more details here 在此处查看更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM