• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Logo

impressive pages: Webdesign und eCommerce

  • Home
  • Blog
  • Hosting
  • Contact
Start » Blog » Set brand property (pa_brand) for all products

Set brand property (pa_brand) for all products

22. December 2021 Leave a Comment

We use the following code to programmatically set the pa_brand (German: Marke) property for all products at once.


add_action('admin_init', 'iphf_add_brand_for_all_products');
function iphf_add_brand_for_all_products() {
	$queryArgs = array(
		 'post_type' => 'product',
		 'posts_per_page' => -1
	);

	$my_query = new WP_Query( $queryArgs );

	if( $my_query->have_posts() ) {

	   while ($my_query->have_posts()) : $my_query->the_post(); 

		 $term_taxonomy_ids = wp_set_object_terms( get_the_ID(), 'mein-marke', 'pa_brand', true );
		 $thedata = Array('pa_brand'=>Array(
		   'name'=>'pa_brand',
		   'value'=>'meine-marke',
		   'is_visible' => '1',
		   'is_taxonomy' => '1'
		 ));
		 update_post_meta( get_the_ID(),'_product_attributes', $thedata); 

	   endwhile;
	}

	wp_reset_query();
}

With is_visible a 1 (true) comes when the brand is to be displayed on the product page as “additional information”. If not required, then insert 0. My brand (in bold in the code) must be replaced by the title form (slug) of the brand. The value for the title form can be found in the editing mask of the property (Products -> Properties -> Configure terms at brand and then edit at the corresponding brand).

It is important to remove this code after execution so that the code is not executed every time the admin area is loaded and loading is delayed.

Filed Under: WooCommerce

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search

Recent Posts

  • WooCommerce: Show free shipping only
  • Remove wrapper DIVs (.wrap) in Genesis
  • Remove the number of products in the category list from the category name
  • Change the number of similar products in WooCommerce
  • Genesis Visual Hook Guide

Categories

  • development
  • Genesis framework
  • Google Search Console
  • mobile
  • SEO
  • Uncategorized
  • Web hosting
  • WooCommerce
  • WordPress

Archives

  • May 2022
  • January 2022
  • December 2021
  • imprint
  • Data protection

Footer

!pages
Heinrich Franz
Wilhelm-Martin-Str. 4
76356 Weingarten (Baden)
instagram
+49 160 85 40 725
info@impressive-pages.de

In my Blog I publish articles about WordPress, Genesis framework und SEO.

© 2022 impressive pages

  • Deutsch