Tagged: Order Notes, woocomerce
-
AuthorPosts
-
August 10, 2024 at 8:55 pm #1464359
Hello,
I’ve installed Woocommerce with my Enfold template and on checkout page, the Order Notes are hidden by default and customers have to click a checkbox to display it.
I would like to have the textarea visible by default and no checkbox to toggle it.
Can you help me?
Thanks,
Best Regards- This topic was modified 3 months, 1 week ago by Empatica.
August 11, 2024 at 3:23 pm #1464400Hey Empatica,
Thanks for your login, first you had a JavaScript error on your site in the child theme file “custom.js” I fix it for you.
Then I research showing the “order notes” by default, although there are many “solutions” online, I find none work in my test.
So I added this to your functions.php and it seems to work:function auto_click_order_notes_checkbox() { ?> <script type="text/javascript"> document.addEventListener('DOMContentLoaded', function() { const orderNoteCheckbox = document.querySelector('.woocommerce-checkout .wc-block-checkout__add-note #checkbox-control-0'); if (orderNoteCheckbox && !orderNoteCheckbox.checked) { orderNoteCheckbox.click(); } }); </script> <?php } add_action('wp_footer', 'auto_click_order_notes_checkbox');
Please check.
For future readers, for some reason the element was different on my test site so I had to use the following, if the above doesn’t work for you try this instead:
function auto_click_order_notes_checkbox() { ?> <script type="text/javascript"> document.addEventListener('DOMContentLoaded', function() { const orderNoteCheckbox = document.querySelector('.woocommerce-checkout .wc-block-checkout__add-note #checkbox-control-1'); if (orderNoteCheckbox && !orderNoteCheckbox.checked) { orderNoteCheckbox.click(); } }); </script> <?php } add_action('wp_footer', 'auto_click_order_notes_checkbox');
Best regards,
MikeAugust 11, 2024 at 11:48 pm #1464426Thanks Mike,
It seems to work properly, I’ll do some more testing and let you know if I find an issue.
Best regards!August 12, 2024 at 8:25 pm #1464487Hey Mike,
I’ve add the WooPayment addon and the plugin “Order Delivery Date” for the customers to select the delivery date/time.
And your code stopped working, I’ve tried with the second one, with both together but still didn’t work anymore.
Do you have any idea?
I really appreciate your help.
Thanks
Best regards!August 13, 2024 at 6:46 am #1464509Hi,
Thank you for the update.
The checkbox “Utilitzeu la mateixa adreça per a la facturació” is checked whenever we view the checkout page, so the script seems to be working as expected. Could you please provide a screenshot of the issue? You can use platforms such as Savvyify, Imgur, or Dropbox to upload and share the screenshot.
Best regards,
IsmaelSeptember 2, 2024 at 7:26 pm #1466070Hello Ismael,
Sorry to answer so late, I was out for holidays.
The checkbox “Utilitzeu la mateixa adreça per a la facturació” is not the one with the issue.
Check at the bottom of the checkout page, the checkbox “Afegiu una nota a la vostra comanda” I would like to have it checked by default and the Textarea for the customers to write a note displayed by default.
First it was working with Mike’s code, but after adding the payment method it stopped working.
Thanks for your help.
RegardsSeptember 3, 2024 at 4:41 am #1466079Hi,
Thank you for the clarification.
We adjusted the edited the functions.php file and adjusted the script a bit. Please make sure to purge the cache before checking.
function auto_click_order_notes_checkbox() { ?> <script type="text/javascript"> jQuery(window).on('load', function() { var orderNoteCheckbox = jQuery('.woocommerce-checkout .wc-block-checkout__add-note #checkbox-control-1'); if (orderNoteCheckbox.length && !orderNoteCheckbox.is(':checked')) { orderNoteCheckbox.click(); } }); </script> <?php } add_action('wp_footer', 'auto_click_order_notes_checkbox');
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.