Compare woocommerce _sku with custom meta_key

I would like to compare two fields – stock and my custom meta_key, to limit the display of products whose inventory is smaller than my custom key.
Example:
I have a product whose inventory is 3, and meta_key – hide_if_stock is equal to 5, but I do not know how to substitute the value of “hide_if_stock” instead of the value.

add_action( ‘woocommerce_product_query’, ‘hide_stock_products’ );

function hide_stock_products( $q ){

$meta_query = $q->get( ‘meta_query’ );

if ( get_option( ‘woocommerce_hide_out_of_stock_items’ ) == ‘no’ ) {
$meta_query[] = array(
‘key’ => ‘_stock’,
‘value’ => ‘1’, //my meta_key value ‘hide_if_stock here
‘compare’ => ‘>’
);
}

$q->set( ‘meta_query’, $meta_query );
}

Read more here:: Compare woocommerce _sku with custom meta_key

Leave a Reply

Your email address will not be published. Required fields are marked *