douchensou6969 2016-09-22 07:07
浏览 26

以编程方式创建产品差异?

I am trying to create product variation in woocommerce and using following code for insert variation post type.

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');
}

This is working fine but it is not set auto book type, i have to select attribute from the drop down option but i want it should auto selected attribute according attribute values. Following screenshot which is showing to me:

enter image description here

but i want like following screenshot

enter image description here

So can you help me how do set attribute for variation products, my code is perfect or something do else.

  • 写回答

1条回答 默认 最新

  • dpc46827 2016-09-23 06:01
    关注

    I was entering wrong attribute name so i have corrected that like below:

    update_post_meta($attID, 'attribute_book-type', $bookTag);
    

    Here book-type is my attribute name which would be passed.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算