每当有人购买产品测试时,都会创建一个新帖子并保存在该类别下,其中后置元素设置为将“order_id”键设置为订单的order_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 );
}
答案 0 :(得分:0)
我认为您想要创建一个包含postmeta的新帖子' 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);
}