Import brands for use with the WooCommerce Brands plugin

This code imports product brand names into the "product_brand" taxonomy if you are using the WooCommerce Brands plugin. Here's how to make it work.


Brand names will only be imported AFTER your Product Sets update.


Create a custom plugin

If you haven't done so already, create a custom plugin.


Add custom code

Add the following code to your custom plugin.

 * Adds the brand name to the 'product_brand' taxonomy.
 * This will import the brands into the 'product_brand' taxonomy when using
 * the WooCommerce Brands plugin.
 * @link
 * @param array $taxonomies The currently configured array of taxonomies.
 * @param array $post An array of post data including ID, post_title, post_status, etc...
 * @param array $product An array of product data returned from the Datafeedr API.
 * @param array $set A post array for this Product Set with an array key of postmeta containing all post meta data.
 * @param string $action The action the Product Set is performing. Value are either "insert" or "update".
 * @return array Updated $taxonomies array
function mycode_add_product_brand_taxonomy( $taxonomies, $post, $product, $set, $action ) {

	$taxonomy = 'product_brand';
	$brand    = ( isset( $product['brand'] ) ) ? trim( $product['brand'] ) : false;

	if ( ! $brand ) {
		return $taxonomies;

	$term = term_exists( $brand, $taxonomy );

	if ( $term !== 0 && $term !== null ) {
		$taxonomies[ $taxonomy ] = ( is_array( $term ) ) ? $term['term_id'] : $term;
	} else {
		$term = wp_insert_term( $brand, $taxonomy );
		if ( is_array( $term ) ) {
			$taxonomies[ $taxonomy ] = $term['term_id'];

	return $taxonomies;

add_filter( 'dfrpswc_filter_taxonomy_array', 'mycode_add_product_brand_taxonomy', 10, 5 );


Save your changes.


Delete Brand attribute (optional)

Lastly, since you don't need the "Brand" attribute anymore, go here WordPress Admin Area > Products > Attributes and delete the "Brand" attribute from that page.

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