Home Forums Backend Issues (wp-admin) Trying to integrate acf_form() into WooCommerce Checkout


Trying to integrate acf_form() into WooCommerce Checkout

  • Hi all,

    So, I’m trying to add user meta fields to the checkout process for WooCommerce. I’m using the Memberships and Subscriptions add-ons.

    I’ve got a hook where I can add a function which calls my ACF form in the correct place:

    function add_acf_form_to_account_creation() {
    	if( is_checkout() ) {
    		if( function_exists( 'acf_form' ) ) {
    			$account_args = array(
    				'form'		=>	FALSE, // This is being integrated into the checkout form
    				'field_groups'	=>	array( 'group_572764d440f6d' ), // The group ID for my fields
    			acf_form( $account_args );
    add_action( 'woocommerce_checkout_after_customer_details', 'add_acf_form_to_account_creation' );

    However, the user meta is not being saved to the newly-created user. I assume it’s because the user ID doesn’t exist when the ACF form fires. I added this line to the $account_args array, but it didn’t work:
    'post_id' => 'user_' . $user_id,

    Can you help?

  • I’ve never worked with something like this but I am assuming that it is what you suspect. The values are probably being save to whatever post is being created by the plugin you mentioned.

    The way I would work around this issue is to create either an acf/save_post filter or a WP save_post filter. The reason I say either is because I’m not 100% sure that the acf/save_post action will fire given the way you’re using the ACF field. Thinking about this it would be better if it’s possible to do this using an acf/pre_save_post filter, but again, I’m not 100% certain that this action will fire either. You’ll need to do some testing so see which filter you can use.

    I’d start with acf/pre_save_post
    and then try acf/save_post
    and if both of those fail I’d move on to WP save_post

    In the filter I’d get the values that are being saved to the post and update the values to the user.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Trying to integrate acf_form() into WooCommerce Checkout’ is closed to new replies.