在woocommerce中单击chechout页面后如何创建自动发布?

在woocommerce中单击chechout页面后如何创建自动发布?,woocommerce,Woocommerce,每当有人购买产品测试时,都会在类别下创建并保存一个新的post,并将post元设置为键“order\u id”,设置为订单的order\u id add_action( 'woocommerce_after_checkout_validation', 'test3' ); function test3(){ global $woocommerce; print_r($woocommerce); $my_post = array(

每当有人购买产品测试时,都会在类别下创建并保存一个新的post,并将post元设置为键“order\u id”,设置为订单的order\u id

add_action( 'woocommerce_after_checkout_validation', 'test3' ); 
    function test3(){ 
        global $woocommerce; 
        print_r($woocommerce); 
        $my_post = array( 
            'post_title' => 'Test', 
            'post_content' => 'This is test post', 
            'post_status' => 'publish', 
            'post_author' => 1, 
            'post_category' => array( 8,39 ) 
          ); 

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

我想你想在结帐完成后创建一个Posteta'order_id'=>45的新帖子?如果是这样,我的代码将帮助您

add_action('woocommerce_new_order', 'order_check', 10, 1);

function order_check($order_id) {

    $my_post = array(
        'post_title' => 'Test',
        'post_content' => 'This is test post',
        'post_status' => 'publish',
        'post_author' => 1,
        'post_category' => array(8, 39)
    );

    // Insert the post into the database
    $post_id = wp_insert_post($my_post);
    add_post_meta($post_id, 'order_id', $order_id);
}

请添加一些代码,您尝试过什么吗?添加操作('woocommerce'u-after'u-checkout\u-validation','test3');函数test3(){global$woocommerce;print\r($woocommerce);$my\u post=array('post\u title'=>'Test','post\u content'=>'这是Test post','post\u status'=>'publish','post\u author'=>1','post\u category'=>array(8,39));//将post插入数据库wp\u Insert\u post($my\u post)}这是代码请用您尝试的代码更新您的问题。请告诉我如何才能获得相同操作的购物车数量?请尽快解决。Thanks@adelinahenry,你所说的购物车数量是什么意思?全部产品?没关系,我已经得到了我的答案,我自己谢谢。。我正在谈论它。foreach($order->get_items()作为$item_id=>$item){$qty=$item['qty'];