如何更改WooCommerce中添加产品的所有产品的后期元数据?
因此,我使用woocommerce并使用名为WP-All-Import的插件将产品数据库导入到Quickbooks连接的电子商务平台中。现在,我需要在完成后将所有产品的元数据“_sync_status”更改为“打开”。我将如何为所有产品添加它们?如何更改WooCommerce中添加产品的所有产品的后期元数据?
您首先需要获取所有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;
我需要将其嵌入到某个东西中吗?或者我可以将它放在那里吗? –
如果你把它放在'/ wp-content/mu-plugins/update-meta.php'中,每次页面加载时都会运行(所以添加,刷新,删除)。你不需要挂钩任何东西。 – doublesharp
^该目录中的任何文件总是由WordPress执行,“mu”代表“必须使用” – doublesharp
您可以使用MYSQL中的更新查询来完成此操作。或者在产品循环中使用ADD_META函数。 –
你好@VinaySharma我是一个相对较新的编码器,你能帮我编码吗? –