Update product price if specific meta_key contains a specific meta_value

Orkhan Hasanli

In Wordpress / Woocommerce database there is a wp_postmeta table.

I am try to update the meta_value = '0' where meta_key = '_price' only if another meta_key = 'group' and meta_value = 'glass' exist for the same post_id.

This is what I have tried:

UPDATE wp_postmeta SET meta_value = '0'
WHERE meta_key = '_price' AND meta_key = 'group' AND meta_value = 'glass';

And This one too:

  UPDATE 
        `wp_postmeta` 
    SET 
        `meta_value` = '0' 
    WHERE 
        meta_key = '_price' 
        AND `meta_key` IN (
            SELECT 
                `meta_value` = 'glass' 
            FROM 
                `wp_postmeta`
        );

Those attempts doesn't work.

How can I update the meta_value = '0' (for meta_key = '_price') only if the meta_key = 'group' and meta_value = 'glass' exist for the same post_id?

Any help is appreciated.

enter image description here

LoicTheAztec

Try this:

UPDATE wp_postmeta as pm
INNER JOIN wp_postmeta as pm2 on pm.post_id = pm2.post_id
SET pm.meta_value = '0'
WHERE pm.meta_key = '_price'
AND pm2.meta_key = 'group' 
AND pm2.meta_value = 'glass';

it should work

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Update meta_value for specific word

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

Using SQL query to update meta_key='_price' with value in meta_key='_regular_price'

orderby price meta_value which contains comma - wordpress

Specific SQL query (multiple meta_value / same row)

Update table wp_postmeta column meta_value where meta_key column equals certain value

conditional logic for css if a selection field (with meta_key) have specific value using ajax/jquery

Avoid cart items price update for specific product categories in Woocommerce

Custom Price for a specific product in Woocommerce

Filter by custom field 'meta_key', 'meta_value' for archive

Construct MySQL query ( meta_key/meta_value table)

After buying a specific product add a user meta

How to replace link to specific file type in wordpress database in meta_value?

How to update user meta for multiple meta_key in wordpress

If the product does not have the "_price" meta key, remove the product

Conditionally alter specific product price in Woocommerce

Trigger an action when a specific price is applied to the product

WooCommerce sql query to find products with a specific meta key and meta value

Sort Woocommerce Products from a product category and custom meta_key

How to check the weight of product in cart based on meta_key?

Assign custom field price as product price to specific user role in WooCommerce

WooCommerce product price visibility: add price back only for a specific category

Set a specific product price conditionally on Woocommerce single product page & cart

Getting 'meta_value' when searching for matching 'post_id' and 'meta_key', 'meta_value' combo

update JsObject value for a specific key

Updating meta value for specific ids

Remove specific WooCommerce categories from single product meta section

Woocommerce MySQL to update price of products in specific category

How to update meta_value to wp_postmeta

TOP Ranking

HotTag

Archive