如何在Wordpress / Woocommerce产品中获得后期父母

时间:2014-02-09 17:53:32

标签: php wordpress woocommerce

我有一个前端表单,允许用户通过前端表单将产品发布到我们的Woocommerce商店。

我正在使用下面的代码,以便上传的每个产品都设置为可变产品,而不是简单的产品。

我正在使用Wordpress wp_insert_post插入这些“变体”,但我无法获得后期父ID(产品ID)

任何人都可以提供任何帮助吗?

这是我到目前为止所做的:

global $wc_product_vendors, $woocommerce, $post, $product;
$product_id = $post->ID;
    $i=1;
         while ($i<=3) {

        // Create post object
        $my_post = array(
          'post_title'    => 'Variation #' . $i . ' of ' . wp_strip_all_tags( $_POST['post_title'] ),
          'post_name'     => 'product-' . $product_id . '-variation-' . $i,
          'post_status'   => 'publish',
          'post_parent'   => $product_id,
          'post_type'     => 'product_variation',
          'guid'          =>  home_url() . '/?product_variation=product-' . $product_id . '-variation' . $i,
          'post_author'   => $vendor_data->term_id
        );

        // Insert the post into the database
        wp_insert_post( $my_post );
        $i++;
        } //endwhile

目前我正在使用$product_id,但它没有给我发布父(产品)ID

0 个答案:

没有答案