You could hook a custom post creation function to the woocommerce_thankyou
action that is fired on the thank you page after the order has been created. This action gives you the $order_id
as a parameter.
The post creation function could be something like this,
function create_post_after_order( $order_id ) {
if ( $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
$content="<ul>";
// I'm not entirely sure of this, please the check that the methods are correct
foreach ( $order_items as $item_id => $item_data ) {
$product = $item_data->get_product();
$content .= '<li>' . $product->get_name() . '</li>';
}
$content .= '</ul>';
$postarr = array(
'post_title' => "Order {$order_id}",
'post_content' => $content // I'm not sure if you need to turn the tags into html entities or if wp_insert_post accepts the content as is
// add more args as needed
);
$new_post_id = wp_insert_post( $postarr );
}
add_action( 'woocommerce_thankyou', 'create_post_after_order' );