I’m working on a project where I have to add custom fields to my WooCommerce Checkout page, I don’t want to use the plugins like WooCommerce Checkout manager as it’s not suitable and limited in functions.
I decided to use ACF to make it works, I’m looking for a way, if ACF supported, so we can add ACF fields to WooCommerce page.
Can you please help me on that?
You could create a page, then create an ACF group that appears only on this specific page, and then finally edit the WC checkout template to call upon these fields, using the page’s ID – get_field( ‘field_name’, $page_id ).
If creating a page for this purpose seems inelegant, you could use this plugin that allows you to use ACF on widgets:
In your theme’s functions.php, register a new widget area for use on your checkout, then create an ACF group for this widget, insert it in and configure it. The plugin’s documentation has some specific instructions on how to call the fields on your template, but feel free to ask if you have any doubts.
I have added the fields to the checkout page successfully; now I’m making it save data to Order detail, everything works file but for upload fields.
It works perfectly for the logged-in user, but for not the logged-in user, it shows the basic upload file selector, when it POST and save to order detail, I only can see the path of the file is C://fakepath/filename.
Do you know why it’s happening?
You can take a look at demo here: http://demo.catsplugins.com/acf-for-woocommerce/?add-to-cart=13
You can only access the file’s name and a few other properties after it already has been uploaded, using the $_FILES superglobal on your PHP script.
You then have to complete the upload process by moving/renaming the uploaded file (which is stored in a temporary folder) into your chosen directory, otherwise it will be automatically deleted by PHP at the end of the script.
You can also use a built-in WordPress function:
The problem i’m facing is:
+ Not login, basic upload
+ Leave “First name” field of WooCommerce blank
+ Press checkout, the file you choosed will be uploaded.
+ Not login, basic upload
+ Fill all fields of WooCommerce
+ Press checkout, no file uploaded. You will be redirected to Order received page
So I think that Scence 2 not working because it’s lacking of some function or a properly action/hook.
It would be great if I can debug and see what’s missing but I can’t enable for not-logged-in user.
could you share your code?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2019 Advanced Custom Fields. Subscribe