How to get customfield value by woocommerce product ID

by ilanb   Last Updated January 13, 2018 16:08 PM

I try to get value of woocommerce customfield from a array of product ID. No luck, I'm on custom page not on woocommerce loop

tried this : $productArray1 is a list of product ID (and it's working)

global $wpdb;
                        global $product;

                        foreach ($productArray1 as $value)
                        {
                            $querystr = "
                            SELECT meta_value 
                            FROM $wpdb->postmeta.meta_key
                            WHERE $wpdb->postmeta.meta_key = 'product_cip' 
                            AND $wpdb->posts.$product->ID=$value
                            ORDER BY meta_value DESC
                            ";

                            $productsCIP = $wpdb->get_results($querystr, OBJECT);

                            if ( ! $productsCIP ) {
                                $wpdb->print_error();
                            }
                            else {
                                echo $productsCIP;
                            }
                        };

I can get all product with same customfield like this :

$products = wc_get_products( array( 'product_cip' => '3337875548519' ) );
                    echo 'PRODUCT WITH SAME CIP (TOTAL : '.count($products).')<br>';

But I need to find 'product_cip' by product ID. Any clue ? Thanks for help



Related Questions



Add a product custom field's value to custom tab

Updated June 02, 2015 22:03 PM

Woocommerce + different contact form in each product page

Updated September 28, 2016 09:03 AM

Calculate the total of 2 meta values and ORDERBY

Updated July 03, 2015 15:03 PM