Skip to main content
deleted 25 characters in body
Source Link

This may help; this function returns a list of product where a custom field is set to any value.

function get_wc_products_where_custom_field_is_set($field) {
  $products = wc_get_products(array('status' => 'publish'));

  foreach ($products as $product) {
    $id = $product->get_id();
    $ret = array();
    if (get_post_meta($id,$field,true)) /* if my custom field is set */
      $ret[] = new \WC_Product($id);
  }
  return $ret;
}

Works fine unless you've got 1000s of products.....

This may help; this function returns a list of product where a custom field is set to any value.

function get_wc_products_where_custom_field_is_set($field) {
  $products = wc_get_products(array('status' => 'publish'));

  foreach ($products as $product) {
    $id = $product->get_id();
    $ret = array();
    if (get_post_meta($id,$field,true)) /* if my custom field is set */
      $ret[] = new \WC_Product($id);
  }
  return $ret;
}

Works fine unless you've got 1000s of products.....

This may help; this function returns a list of product where a custom field is set to any value.

function get_wc_products_where_custom_field_is_set($field) {
  $products = wc_get_products(array('status' => 'publish'));

  foreach ($products as $product) {
    $id = $product->get_id();
    if (get_post_meta($id,$field,true)) /* if my custom field is set */
      $ret[] = new \WC_Product($id);
  }
  return $ret;
}

Works fine unless you've got 1000s of products.....

Source Link

This may help; this function returns a list of product where a custom field is set to any value.

function get_wc_products_where_custom_field_is_set($field) {
  $products = wc_get_products(array('status' => 'publish'));

  foreach ($products as $product) {
    $id = $product->get_id();
    $ret = array();
    if (get_post_meta($id,$field,true)) /* if my custom field is set */
      $ret[] = new \WC_Product($id);
  }
  return $ret;
}

Works fine unless you've got 1000s of products.....