Save WooCommerce OrderData in ACF Field
-
My goal is to save WooCommerce order data into an ACF Field in the backend of WordPress. For this project every order which is completed generates a new post in my custom post type named ‘groeiprocessen’. The code for this function looks like this and works perfectly.
—-
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();foreach ( $order_items as $item_id => $item_data ) {
$product = $item_data->get_product();
$content.= $item_data->get_quantity();
$content.= $product->get_name();
}$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’ => ‘groeiproces’,
‘post_status’ => ‘publish’,
);
$post_id = wp_insert_post($new_post);
}
add_action( ‘woocommerce_thankyou’, ‘create_post_after_order’, 10, 1 );—-
Right now the product name and quantity gets saved in the post content.
As you can see I created to ACF Fields under the content field. Now my question is: How can I save the quantity data for the right product in the ACF Fields under my post?
Field ID’s
acf-field_6163f2e1542e1
acf-field_61640103002c9Field names
acf[field_6163f2e1542e1]
acf[field_61640103002c9]I would really appreciate the help. Thanks in advance!
- The topic ‘Save WooCommerce OrderData in ACF Field’ is closed to new replies.