• Resolved nicorubrixcreations

    (@nicorubrixcreations)


    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_61640103002c9

    Field names
    acf[field_6163f2e1542e1]
    acf[field_61640103002c9]

    I would really appreciate the help. Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thanks.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    Since there have not been responses here, I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Save WooCommerce OrderData in ACF Field’ is closed to new replies.