Script update Product description (All Products)

//add_action('init', 'tzn_update_product_description_from_cotent_1');
if ( ! function_exists( 'tzn_update_product_description_from_cotent_1' ) ) {
	function tzn_update_product_description_from_cotent_1(){
		if(current_user_can('administrator') && isset($_GET['update_product_description']) && $_GET['update_product_description'] == "1"){
			$query = new WC_Product_Query( array(
				'limit' => -1,
				'orderby' => 'date',
				'order' => 'DESC',
				'return' => 'ids',
			) );
			$products = $query->get_products();
			if($products && count($products ) > 0){
				foreach($products as $product_id){
					$product = wc_get_product($product_id);
					echo "<br>-- product_id: ".$product_id;

					if (get_field("beschreibung", $product_id )) {
						$beschreibung = get_field("beschreibung", $product_id );
						if(isset($beschreibung['content_1'])){
							$content_1 = $beschreibung['content_1'];
							wp_update_post( 
								array(
									'ID' => $product_id, 
									'post_content' => $content_1
								) 
							);
						}
						
					}
					update_post_meta( $product_id, 'update_product_description_from_cotent', 1 );
					echo "updated";
				}
			}
		}
	}
}

Leave a Reply

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