【问题标题】:WooCommerce front-end product creationWooCommerce 前端产品创建
【发布时间】:2013-05-20 16:00:47
【问题描述】:

好的,我会尝试以一种不会让每个人都对我的困惑感到困惑的方式提出这个问题

我正在尝试为 WooCommerce 制作前端表单,以便客户可以从前端制作产品。 到目前为止,我想要实现的所有其他部分都在工作,即。标题、内容和价格 所有张贴在正确的帖子类型。但无法将其发布到产品类别

WooCommerce 类别是一个名为 product_cat 的自定义分类法

product_cat 子项是术语,我有三个 --> Base、Designs 和 User Designs

我希望此表单中的所有帖子都自动位于用户设计下。这就是我现在拥有的

$post_information = array(
        'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
        'post_content' => esc_attr(strip_tags($_POST['postContent'])),
        'post_type' => 'product',
        'post_status' => 'publish',


    );

$post_id = wp_insert_post($post_information);
  update_post_meta( $post_id, '_regular_price', strip_tags($_POST['_regular_price'] ) ) ;


    if($post_id)
    {
        wp_redirect(home_url());
        exit;
    }

};

我尝试了许多变体来设置术语,例如

 wp_set_object_terms($post_id, 'designs', 'product_cat', false);
 wp_set_post_terms($post_id, 'designs', 'product_cat', false);
 wp_set_object_terms($post_id, $designs ,'product_cat');
 wp_set_post_terms( $post_id, $designs, 'product_cat', true );
 wp_set_object_terms($post_id, $base, 'product_cat');           

不行,我知道我错过了一些东西,但我不知道是什么。我一直盯着屏幕看很久了,眼睛都在交叉,

任何帮助将不胜感激提前感谢

【问题讨论】:

    标签: php wordpress frontend woocommerce


    【解决方案1】:

    使用以下内容:

    wp_set_post_terms( $product_id, '343', 'product_cat');
    

    $product_id 是您正在制作的产品的 post_id343 是分类 ID(您可以从其中一个分类表中获取)

    【讨论】:

      猜你喜欢
      • 2013-07-09
      • 1970-01-01
      • 2021-11-25
      • 2012-07-15
      • 1970-01-01
      • 2013-06-21
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多