Import Custom Product Tags for each Product Set

This article shows you how to control the tags imported for your products on a per Product Set basis.

For example, let's say you have a Product Set for Tents and you want to tag each of those tents with the following three tags:

  1. camping
  2. outdoors
  3. hiking

Here's what you will need to do in order to set that up.

1. Install the Advanced Custom Fields plugin.

2. Add a New Field Group with the settings in the screenshot below.

3. Add the following code to your Custom Plugin (How to create custom plugin)

add_action( 'dfrpswc_pre_save_product', static function ( Dfrpswc_Product_Update_Handler $updater ) {
   if ( ! $acf_field_object = get_field_object( 'dfrps_product_set_tags', $updater->product_set['ID'] ) ) {
      return;
   }

   $updater->wc_product->set_tag_ids( $acf_field_object['value'] ?? [] );
} );

4. Edit your Product Sets and configure the tags to import for each Product Set.

That's it! When your Product Sets update, the tags you enter for each Product Set will be associated with each product in that Product Set.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us