【发布时间】:2015-11-19 02:06:56
【问题描述】:
我有 3000 种产品要上传到网站,所以我试图以编程方式将产品添加到我的 woocommerce 网站得到一些以编程方式添加产品的代码,我不知道如何运行它以及在哪里运行它被困在在小小的帮助之间,我们将不胜感激在哪里运行代码以及如何将多个产品添加到网站。
$post = array(
'post_author' => $user_id,
'post_content' => '',
'post_status' => "publish",
'post_title' => $product->part_num,
'post_parent' => '',
'post_type' => "product",
);
//Create post
$post_id = wp_insert_post( $post, $wp_error );
if($post_id){
$attach_id = get_post_meta($product->parent_id, "_thumbnail_id", true);
add_post_meta($post_id, '_thumbnail_id', $attach_id);
}
wp_set_object_terms( $post_id, 'Races', 'product_cat' );
wp_set_object_terms($post_id, 'simple', 'product_type');
update_post_meta( $post_id, '_visibility', 'visible' );
update_post_meta( $post_id, '_stock_status', 'instock');
update_post_meta( $post_id, 'total_sales', '0');
update_post_meta( $post_id, '_stock', "" );
【问题讨论】:
-
你可能想试试 woocommerce API:woothemes.github.io/woocommerce-rest-api-docs/#create-a-product 还有批量创建者:woothemes.github.io/woocommerce-rest-api-docs/…
-
@Dez 感谢您的回复,所以如果您能详细说明一下如何上传产品,对我理解这一点会更有帮助
标签: php wordpress woocommerce