Where to add acf_header() when using WooCommerce custom My Account layout

Hey there,

I hope someone can guide me:
I have created a custom WooCommerce My Account layout in Pro layout builder.
Just like in Josh Donelly’s tutorial on that topic. Everything is working fine.

Now I need to add some ACF fields on a custom tab of the my account section.
To do that I need to add ACF’s acf_header() before get_header() in my Pro Child Theme, but I cannot figure out, which template file I need to customize in this case. I’m using the Starter stack.

Can you tell me which template file that would be to add the acf_header() into?

Hello @raye,

Thanks for writing in! Instead of having a custom template file, you can use action hooks and add your custom PHP hook in your child theme’s functions.php file. Perhaps this documentation can give you more information:

Be advised that custom coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

Now this to works!
Thank you, @ruenel !

Not sure if this is the best hook to position the acf_form_head() call. I did it like this:

function add_acf_header(){
	acf_form_head();
}
add_action( 'x_before_site_begin', 'pyropixel\membercheck\add_acf_header' );

Just from the naming, I would say this hook is fired quite early when the site is rendered.

What about the x_before_view_{$file} hook. Is this fired even earlier?
If yes, what would the {$file}be in this case?

In QueryMonitor the Template section shows something like the following screenshot:

But I’m not sure what I’m seeing here and if this is helpful, cause many of the files does not exist.
Or is there any other way to find out which file my current page is currently using?

My problem is currently solved as stated above. Just want to know how it works.

Ah, I’m sorry. After playing arround a bit I see that it is NOT working.
I get some Cannot modify header information - headers already sent errors.

I think the hook above is too late and the acf_form_head() is called after any output has been sent.

Any chance to add the funtion earlier?

Hello @raye,

There is something wrong in your custom code. It should be:

function my_function_name(){
	// Things to do here
}
add_action( 'x_before_site_begin', 'my_function_name' );

Hope this helps.

The codee is correct. I’m working with PHP namespaces:namespace pyropixel\membercheck; to prevent naming collisions with other plugins. If you do so, that is the correct way to call the callback functions with hooks.

The thing is, it works when I just display the ACF form, but when the form is sent, it does not work. I.e. the ACF field validation is not triggered. I think the hook is just too late and gets called AFTER get_header() in your template is called.

x_before_view_header_base might be the action you want to hook into.

I would try add_action('get_header', function() {}); as well, messing with the priority on that.

Let us know if that helps and have a great day.