非常感谢你!它给了我一些如何实现iti的想法,我不得不将感谢行动改为付款完成,因为它没有为POS订单或手动订单创建帖子。还有(邮资);似乎不起作用
这是工作代码
function create_post_after_order( $order_id ) {
if ( $order_id instanceof WC_Order ){
return;
}
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
$content = \'<ul>\';
foreach ( $order_items as $item_id => $item_data ) {
$product = $item_data->get_product();
$content .= \'<li>\' . $product->get_name() . \'</li>\';
}
$content .= \'</ul>\';
$new_post = array(
\'post_title\' => "Order {$order_id}",
\'post_content\' => $content,
\'post_status\' => \'private\',
\'post_date\' => date(\'Y-m-d H:i:s\'),
\'post_author\' => $user_ID,
\'post_type\' => \'custom\',
);
$post_id = wp_insert_post($new_post);
}
add_action( \'woocommerce_payment_complete\' , \'create_post_after_order\' );