【问题标题】:Woocommerce Add Product with External/Affiliate TypeWoocommerce 添加具有外部/附属类型的产品
【发布时间】:2014-06-08 10:51:11
【问题描述】:

我正在尝试以编程方式(使用 PHP)将 Woocommerce 产品插入我的网站。我所有的产品都是外部/附属产品类型。我已经使用下面的代码成功创建了一个产品,但它默认为“简单产品”产品类型。我的问题是如何使用我的 PHP 帖子创建或元数据更新将产品类型更改为 External/Affiliate?

我试过这个命令没有成功:

update_post_meta($post_id, 'product-type' , 'external' );

这是用于创建分配了基本属性的产品的代码:

require_once("../wp-load.php");

$new_post = array(
    'post_title' => "Title of My Product",
    'post_content' => 'Full description of My Product',
    'post_status' => 'publish',
    'post_type' => 'product',
    'is_visible' => '1'
);

$post_id = wp_insert_post($new_post);
update_post_meta($post_id, '_sku', '5000' );
update_post_meta($post_id, '_regular_price' , '99.95');
update_post_meta($post_id, '_product_url' , 'http://www.myaffiliatesURL.com');
update_post_meta($post_id, '_button_text' , 'Buy from My Affiliate' );
update_post_meta($post_id, '_aioseop_description' , 'Short description of My Product' );
update_post_meta($post_id, '_visibility' , 'visible' );

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    可以试试这个。

    wp_set_object_terms ($post_id, 'external', 'product_type');
    

    你还需要设置'parent_id'

    【讨论】:

      【解决方案2】:

      我想通了!感谢您的评论以提供帮助。这是将其设置为外部/附属的代码:

      wp_set_object_terms( $post_id, 8, 'product_type', false );
      

      这里的关键是使用 8 表示外部/附属

      【讨论】:

      • (wp_set_object_terms( $post_id, 8, 'product_type', false ); ) 的文件名是什么...???
      猜你喜欢
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 2017-06-26
      • 2019-07-11
      相关资源
      最近更新 更多