2015-10-20 22 views
0

因此,我使用woocommerce並使用名爲WP-All-Import的插件將產品數據庫導入到Quickbooks連接的電子商務平臺中。現在,我需要在完成後將所有產品的元數據「_sync_status」更改爲「打開」。我將如何爲所有產品添加它們?如何更改WooCommerce中添加產品的所有產品的後期元數據?

+0

您可以使用MYSQL中的更新查詢來完成此操作。或者在產品循環中使用ADD_META函數。 –

+0

你好@VinaySharma我是一個相對較新的編碼器,你能幫我編碼嗎? –

回答

1

您首先需要獲取所有WooCommerce產品(「產品」的發佈類型),循環遍歷每個產品,並更新每個產品的發佈元。您可以將此代碼放入主題中的functions.php/wp-content/mu-plugins「必須使用」插件目錄中的文件或匿名使用WordPress Developer + Console等插件來運行此代碼。

// args to fetch all products 
$args = array(
    'post_type' => 'product', 
    'posts_per_page' => -1 
); 

// create a custom query 
$products = new WP_Query($args); 

// if products were returned... 
if ($products->have_posts()): 
    // loop over them.... 
    while ($products->have_posts()): 
     // using the_post() to set up the $post 
     $products->the_post(); 

     // use $post->ID to update the '_sync_status' post meta value 
     update_post_meta($post->ID, '_sync_status', 'on'); 
    endwhile; 
endif; 
+0

我需要將其嵌入到某個東西中嗎?或者我可以將它放在那裏嗎? –

+0

如果你把它放在'/ wp-content/mu-plugins/update-meta.php'中,每次頁面加載時都會運行(所以添加,刷新,刪除)。你不需要掛鉤任何東西。 – doublesharp

+0

^該目錄中的任何文件總是由WordPress執行,「mu」代表「必須使用」 – doublesharp

相關問題