Your issue here likely is the action ‘publish_product’ not firing – it only runs when you first create a product, or set a products status from Draft or Pending Review to Publish.
Be aware that wp_set_object_terms will overwrite any other existing category data with the last parameter set to false, in your code those products would end up with only the one new category.
Since you are just changing one category to another is there a reason why your not just giving the existing categories new names and slugs?
You could also just do this through the bulk edit facility – under screen options you can up the view to say 500 products at a time and still will perform ok (depending on your set up could be slow but you’d still get through 10,000+ products in 20 minutes).
Lastly just for future reference all your $category variables are only single values (intergers) so no need for array().
Related Posts:
- Display All Products by Category with WooCommerce
- Woocommerce get category image full size
- Programmatically create product category and add thumbnail in woocommerce
- Reflect nested categories in appearance > menus
- Create product category and keyword search form in woocommerce? [closed]
- How do I edit pre_get_post for the category the user is currently in?
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- How to select product category while adding new product in woocommerce? [closed]
- Hide uncategorized products from the shop page
- display woocommerce all category title on home page
- Add Product categories to WordPress menu without losing hierarchy
- Display “add to cart” button on every listing in product category page?
- Getting categories id for all products in cart
- Get woocommerce catogry
- Set post categories to include parents when setting child category
- Woocommerce category show subcategories only/omit posts for specific category
- Omit specific product categories from WooCommerce shortcode
- products nested by subcategories in a current category archive
- WC 3.x Get categories from variable product of the cart
- need to add custom field in more products
- How to redefine the sorting of product categories by menu_order?
- Pagination not visible on woocommerce’s category page
- Pagination is not working properly in Product Category/Tag pages
- Best way of getting WooCommerce category path
- How to recreate a copy of a product category in WooCommerce? [closed]
- Get parrent category name
- Sorting category products not working
- Remove product category placeholder image (Woocomerce)
- Change thumbnail image depending product category
- Unwanted Duplicate Product Categories in WooCommerce
- Woocommerce custom category pages
- Customize WordPress widget – Product Category
- WooCommerce – How to show specific category first-rest of products-specific category last
- Categories are not listing their respective products
- Display single category name in woocommerce loop
- Building Menu from Woocommerce Product Categories
- Include WooCommerce product to all child categories
- woocommerce related products by specific categories [closed]
- List just subcategory and products of active category page in Woocommerce
- Display all product tags associated with a specific product category
- why get_the_post_thumbnail( the_ID()) echos extra post id
- How to access deleted term inside delete_product_cat action
- Filter WooCommerce archive pages by an additional category
- Custom tax_query filter not working for Woocommerce product categories
- How do order product categories – on a parent category page – in Woocommerce?
- Adding custom ID field to the categories
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Woocommerce search form with category select
- How to display product with two condition, category and brand taxonomy
- Show different menu on each woocommerce category page
- Template for product-category page [closed]
- displaying the last product comment in the woocommerce category
- Displaying Single Product Page Parent and Child Category
- Woocommerce only display child category when parent is checked (on add new product page)
- category description not showing in my woocommerce
- Conditional label Woocommerce archive [unsolved]
- Show audio player only in specific post type category
- How to make product image inherit from category image
- How to set acf color field as background color to product category
- How to target all woocommerce categories that don’t have any subcategories in them?
- In if…else condition, the else statement shows even if if statement is correct
- How to show WooCommerce Categories on ‘shop’ page instead of products?
- Show the parent taxonomy by creating shortcode in woocommerce?
- How can I display all products from all categories on one page with woocommerce?
- How to add all subcategories as submenu in WordPress menu
- How to edit woocommerce sub-category page
- in post content shortcode works, but hardcoded in same page template doesn’t?
- Is there a reason to put a product in both the Child and Parent Categories?
- WordPress category title not update in navigation menu
- WooCommerce showing active product categories on single product page
- selecting categories that have products with tag/category
- Restrict retrieved terms by category?
- How to fix 404 error in pagination in categories of woocommerce with common url base /shop/?
- Woocommerce Category Sort Dropdown
- Woocommerce: all products of all categories instead products of one category
- How to delete WooCommerce categories in bulk that only have one product
- Product Category page showing all products
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- product_cat image url from database
- How to get WooCommerce Product Categories and its children’s children?
- Woocommerce change tag_id to name
- set a parent category in a product woocommerce
- No results found for second level category
- Categories and Tags Conflict after Woocommerce Installation
- Category menu that filters out empty categories
- woocommerce – products by category slug? [closed]
- How can I add a Categories page link to a menu? [closed]
- Custom Woocommerce Category view
- Displaying categories and subcategories without link
- WooCommerce category display in custom page
- Sorting Woocommerce products by category and attributes
- Woocommerce custom taxonomy order
- Update wordpress menu with woocommerce products
- How to get Woocomerce categories count
- Woocommerce – Display product category of product in Orders page
- Get all categories
- Categories and products woocommerce wordpress
- Function to reference post meta in place of category Woocommerce
- Add custom fields to Woocommerce Category Page