You just need to add a missing boolean argument in wp_set_object_terms()
function like:
wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);
This time the term will be appended and not replaced.
You should check that the term doesn’t exist yet on the product, before appending it like:
add_action( 'transition_post_status', 'new_product_add', 10, 3 );
function new_product_add( $new_status, $old_status, $post ) {
if(
$old_status !== 'publish'
&& $new_status === 'pending'
&& ! empty($post->ID)
&& $post->post_type === 'product'
) {
$taxonomy = 'product_cat';
$term_id = get_term_by( 'name', 'parent_category', $taxonomy )->term_id;
if( ! has_term( $term_id, $taxonomy ) ) {
wp_set_object_terms( $post->ID, $term_id, $taxonomy );
}
}
}
Related Posts:
- How to change / delete product short description in Woocommerce
- Change description on specific WooCommerce product status change
- Exclude product attributes from taxonomy terms loop
- WordPress using get_term to retreive slug not working as expected
- Displaying custom taxonomy on WooCommerce product page
- Sum the total amount of a specific product purchased per user and display in table
- Change “add to cart” button color based on Woocommerce product category [closed]
- How can I get the values of my WordPress $wpdb query in Jquery?
- How can I pass a custom/dynamic product to the Woocommerce cart?
- Add to cart function not working for first product when cart is empty [closed]
- I want to add custom add to cart link [closed]
- How to make products with no cost in WooCommerce
- Woocommerce : Can’t get product info in loop
- WooCommerce custom product dimensions
- Trouble checking if custom woocommerce checkout field is empty or not
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Validation algorithm in checkout field
- Get term siblings of current child taxonomy
- How to get post’s current parent term ID?
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- My new button is in the wrong place
- Insert term and child term from frontend
- WordPress Woocommerce – Product Type [closed]
- Pagination for custom shop loop woocommerce
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Woocommerce change prices for a certain country [closed]
- How to get private property in parent class into extended class?
- echo something inside a shortcode
- Replace Woocommerce “add to cart” to be “Download” button [closed]
- Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
- List taxonomy term slugs within shortcode (do_shortcode)
- get taxonomy thumbnail and use it as a variable in code
- Woocommerce Email attachments not working – file not being attached
- Include Parent Term in wp_list_categories
- Function returns text instead of html [closed]
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Single Quotes in .php file doesn’t load website
- Add post with approval by the admin
- How can I access string value in an array?
- Copy taxonomy terms from one post to another programmatically
- get_total () returns 0 – woocommerce [closed]
- Limit Taxonomy Output in Conditional Statement
- How to remove coupon dropdown feature
- Get all categories post is not in
- How can I display a div ONLY if it is not a certain term page
- Woocommerce display one random product via php
- Hide image if taxonomy term is empty
- Isotope Drop Down Categories Filter Function
- Change product_base programmatically
- How to filter custom taxonomy term name, slug, and description?
- Add html link in functions.php files of the theme
- require_once() if a product in woocommerce contains a tag [closed]
- How to optimize update_post_meta?
- How to upload WP user avatar on woocommerce account page [closed]
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- Remove item in Checkout
- email alert for product availability
- How to relocate paypal button gateway on checkout page in woocommerce
- How to rename woocommerce-billing-fields
- Can a plugin redirect product page based on IF condition?
- Hierarchical taxonomy list with modificated term links
- Seo Friendly Filter URLs
- How to display SQL query that ran in WC_Order_Query?
- WooCommerce pages looks unstyled
- customize woocommerce templates and display store on home
- How to disable delivery on certain date at checkout page in WooCommerce?
- WC_Customer delete function returns error
- Only show size attributes in product box woocommerce when available
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Remove page title in product page using a function
- woocommerce specific quantities for product
- how can i add class or span tag at sprintf?
- Call WC_Product get_price()?
- How to display a custom product field value of a specific category on a Woo Commerce checkout page?
- Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)
- Personalize checkout text
- Display attribute on shop page after the title
- CSS change in woo commerce Place Order Text [closed]
- Woocommerce – get_items() returns empty array
- How do I run code every 24 hours?
- Disable if there are no children – Woocommerce
- WooCommerce – Moving Product Price to the Left of Add to Cart Button [closed]
- Woocommerce Product_cat for current category page
- WP All Import / Update stock quantity from multiple XML files
- woocommerce related product title length
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- woocommerce wc_create_order(); is creating multiple orders instead of one?
- Create a package of products as one Item in woocommerce?
- Woocommerce: remove total sum from new order’s email [closed]
- Include js script ONLY on woocommerce product category pages? [closed]
- WP_Query multiple post results
- Convert Featured products loop into Recent products loop?
- fetch woocommerce product with custom taxonomy
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Alter Woocommerce product archive structure
- Have Woocommerce show product price if id, when not logged in
- After disabling WPML multi currency, the currency is still handled by the WPML
- custom post type with role Vendor