Woocommerce update price of product by particular category or tag

WordPress product table has relation with 3 tables post, postmeta, term_relationships.

Once we need to update price of particular category or tag products this will take days of time as per the product count but using mysql query we can easily achieve this:

UPDATE 
    `hotandcold_postmeta` 
SET 
    `meta_value` = meta_value + (meta_value * (2.64 / 100))
WHERE 
    meta_key = '_price' 
    AND `post_id` IN (
        SELECT 
            `object_id` AS product_id 
        FROM 
            `hotandcold_term_relationships` 
        WHERE 
            term_taxonomy_id = 827
            AND `object_id` IN (
                SELECT 
                    `ID` 
                FROM 
                    `hotandcold_posts` 
                WHERE 
                    `post_type` = 'product' 
                    AND `post_status` = 'publish' 
                    AND `ID` = `object_id`
            )
    );

Leave a Reply

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