I use Woocommerce Brand Plugin to add brand to the products. When I add a new product and select the brand name I want to appear the same brand name as an attribute as well.
I have added the below code but not sure how can I check the “product_brand” actual taxanomy name, where my brand names are stored in Woocommerce. I didn’t find any settings under Woocommerce for the plugin and also the “brand” attribute name.
I tried this code:
function transfer_brand_to_attribute( $post_id ){
$brand = wp_get_post_terms( $post_id, 'product_brand' );
if ( ! empty( $brand ) ) {
// Get the first brand term
$brand_name = $brand[0]->name;
// Update or add the 'brand' attribute
update_post_meta( $post_id, 'brand', $brand_name );
}
}
add_action( 'save_post', 'transfer_brand_to_attribute' );
Any advice is appreciated.
What do you mean when you say “I want to appear the same brand name as an attribute as well…”? Can you better explain and clarify, editing your question?