Get all WooCommerce products from a category that have specific meta data

Toniq

I have a custom meta on my custom post type:

$arr = array('foo' => 'yes',
             'featured_enabled' => 123,
             'something' => 'abc',
);

update_post_meta($post_id, 'fvp_featured_meta', $arr );

My question is how can I get all products from specific category ID in woocommerce that have this meta (fvp_featured_meta)? (not all posts have this meta)

LoicTheAztec

You can try to use wc_get_products() function to get products that have a specific meta data belonging to a specific product category as follows:

$category_term_slugs = array('clothing; // 

// Get an array of WC_Product Objects
$products = wc_get_products( array(
    'limit'         => -1,
    'status'        => 'publish',
    'meta_key'      => 'fvp_featured_meta',
    'meta_compare'  => 'EXISTS',
    'category'      => $category_term_slugs,
) );

foreach( $products as $product ) {
    echo $product->get_name() . '<br>';
}

It should works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get products with specific attribute term and specific category term in Woocommerce using SQL

Adding Custom Meta Data from Products to Orders items in Woocommerce

Woocommerce MySQL to update price of products in specific category

Exclude specific products from everywhere with a meta query in Woocommerce

Display products from specific product category in Woocommerce

Hide products having a specific product category in Woocommerce

Get all Woocommerce products from current product category term Id in a WP_Query

Set custom quantity arguments to products from specific category in WooCommerce

Get list of products that don't have a specific taxonomy in WooCommerce

Want to get all user's products by category including category that have no product

Sort Woocommerce Products from a product category and custom meta_key

Display with a shortcode a dropdown of Woocommerce products for a specific category

Replace Upsells with products from a specific product category in Woocommerce 3

Filter products from a specific custom meta data in Woocommerce shop page

Display All Products by Category with WooCommerce

How to get all products from current WooCommerce product category?

Get all products with specific meta_key whose meta_value is equal in WooCommerce

Mongoose: Get the data from 2 collections, like get products that have same category type like fruits

Get manufacturers of all products in a category from non-product page

Get (all) post data of specific category into a variabele

Prestashop 1.6 get feature value of products from specific category

how can i get products for specific category from woocommerce restapi using php

WooCommerce hide all products of a certain category if not loggedin

Woocommerce products from category loop

Remove "No products found" from a specific product category in Woocommerce

Woocommerce how to display products from specific category on archive page

How to get all products that doesn't have feature image in woocommerce?

Apply discount on products within specific category (WooCommerce)

WooCommerce: assign a category to all products