我试图在woocommerce中创建产品变体,并使用插入变体帖子类型的以下代码。
foreach ($book_tag as $bookTag) {
$post_name = 'ABE-'.$post_id.'book-type'.$bookTag;
$my_post = array(
'post_title' => 'BookType ' . $bookTag . ' for #' . $post_id,
'post_name' => $post_name,
'post_status' => 'publish',
'post_parent' => $post_id,
'post_type' => 'product_variation',
'guid' => home_url() . '/?product_variation=' . $post_name
);
$attID = wp_insert_post($my_post);
update_post_meta($attID, 'book_type', $bookTag);
update_post_meta($attID, '_price', $bookPrice);
update_post_meta($attID, '_regular_price', $bookPrice);
update_post_meta($attID, '_sale_price', $salePrice );
update_post_meta($attID, '_sku', $post_name);
update_post_meta($attID, '_virtual', 'no');
update_post_meta($attID, '_downloadable', 'yes');
update_post_meta($attID, '_manage_stock', 'no');
update_post_meta($attID, '_stock_status', 'instock');
}这是工作正常,但它不是设置自动图书类型,我必须从下拉选项中选择属性,但我希望它应该自动选择属性根据属性值。下面是向我展示的屏幕截图:

但是我想要下面的截图

所以你可以帮助我如何为变体产品设置属性,我的代码是完美的或其他事情。
发布于 2016-09-23 14:01:46
我输入了错误的属性名称,因此我进行了如下更正:
update_post_meta($attID, 'attribute_book-type', $bookTag);这里book-type是我要传递的属性名。
https://stackoverflow.com/questions/39632413
复制相似问题