-
Posted in : Efor
-
Hello,
I’m struggling to make a change in the woocomerce checkout form. I want to add a new field next to the company field, but without any success. I have tried many plugins and also custom code.
Seems like no filters are called within the child theme.
ex:
add_filter(‘woocommerce_checkout_fields’, ‘custom_override_checkout_fields’);I’ve tried many filters like this without any success. Probably the 3rd party plugins that modifies the checkout form uses also these filter to hook in the changes, but it is not really working.
Can someone advise on this?
I’m using the Efor theme.
Thanks
Hello,
It seems that the issue might be caused by third-party plugins. Here are some steps you can try to resolve the problem:
1. Disable Third-Party Plugins:
Some plugins that modify the checkout form may be using the same filters, which can create conflicts. Try deactivating any third-party plugins that affect the checkout form and see if the issue persists. If the problem is resolved, it may be due to one of these plugins.2. Use the Correct Hook:
The code example you’re using seems to be correct, but make sure the custom code is properly added to the functions.php file in your child theme. Here’s an example of how to add a custom field:function custom_override_checkout_fields($fields) { $fields['billing']['billing_custom_field'] = array( 'type' => 'text', 'label' => __('Custom Field', 'woocommerce'), 'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'), 'required' => false, 'clear' => false, 'priority' => 22, ); return $fields; } add_filter('woocommerce_checkout_fields' , 'custom_override_checkout_fields');This example adds a new custom field to the billing section of the checkout form.
3. Update Themes and Plugins:
Make sure WooCommerce, your theme, and all plugins are updated to the latest versions, as outdated versions may cause filters not to work properly.4. Test with a Default Theme:
Sometimes, child theme modifications can interfere with WooCommerce filters. Try switching to a default theme like Storefront and see if the issue is resolved. If it works with the default theme, there may be a conflict in your child theme.By following these steps, you should be able to identify the cause of the issue.
Let me know if this helps!
Best regards,
MehmetThanks for the feedback.
Looks like the issue is caused by the fact that woocomerce checkout pages uses checkout blocks which from what I read doesn’t support custom fields or I haven’t found yet a way to do it.
If I create a new checkout page and add [woocommerce_checkout] shortcode the filter is called and I can hook in custom logic to the checkout form.
Do you maybe know how to do this with woocomerce checkout blocks?
I’ll keep investigating in the meantime.
Hi,
You’re right that WooCommerce checkout blocks currently don’t fully support custom fields, as they are still in development and may not yet have all the functionality of the classic checkout.
Here are a few suggestions you can try:
– Use the Classic Checkout:
As you mentioned, using the [woocommerce_checkout] shortcode for the checkout page allows you to hook custom logic into the form. For now, this might be the most reliable solution.– Stay Updated on WooCommerce Blocks:
Make sure you are using the latest version of the WooCommerce Blocks plugin, as updates may introduce new features or improvements regarding custom field support.– Custom Development:
If you’d prefer to stick with checkout blocks, adding custom fields will likely require custom development. You may need to use JavaScript and look into filters or hooks specific to the @woocommerce/blocks-checkout package, such as the slotFills feature.– Alternative:
If you find that checkout blocks are limiting for your project, you might want to switch back to the classic checkout temporarily until WooCommerce adds more support for custom fields in blocks.Let me know if you need further assistance. I’m happy to help where I can!
Best regards,
Mehmet
You must be logged in and have valid license to reply to this topic.