Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?
  2. // WooCommerce has a stupid function in the ./assets/js/frontent/woocommerce.min.js file that hides/shows the 'description' elements
  3. // for the checkout fields both when there is an onclick event on the document body, and when any field input is clicked.
  4. //
  5. // The offending code for this 'feature' is the following:
  6. // i(document.body).on("click",function(){i(".woocommerce-input-wrapper span.description:visible").prop("aria-hidden",!0).slideUp(250)}),i(".woocommerce-input-wrapper").on("click",function(e){e.stopPropagation()}),i(".woocommerce-input-wrapper :input").on("keydown",function(e){var o=i(this).parent().find("span.description");if(27===e.which&&o.length&&o.is(":visible"))return o.prop("aria-hidden",!0).slideUp(250),e.preventDefault(),!1}).on("click focus",function(){var e=i(this).parent(),o=e.find("span.description");e.addClass("currentTarget"),i(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),o.length&&o.is(":hidden")&&o.prop("aria-hidden",!1).slideDown(250),e.removeClass("currentTarget")}),
  7. //
  8. // This doesn't work well with some addons like the Custom Checkout Fields plugin, where the description is show when the page
  9. // loads, but then it hides wheneven the user clicks anywhere on the checkout page.
  10. //
  11. // Or sometimes you might not want this default behaviour to occur at all, and this code will disable it without having to
  12. // edit the actual woocommerce.min.js file.
  13. //
  14. // Add the following code to your theme's functions.php file to disable this stupid feature once and for all!
  15.  
  16. function disable_woocommmerce_hide_description_checkout_fields() {
  17. if (is_checkout()) {
  18. wc_enqueue_js("
  19. $(function() {
  20. // Prevent WooCommerce hide description function that is bound to document.body
  21. $(document.body).off( 'click');
  22. // Prevent WooCommerce hide description function that is bound to inputs
  23. $('.woocommerce-input-wrapper :input').off('click focus');
  24. });
  25. ");
  26. }
  27. }
  28. add_action('wp_enqueue_scripts', 'disable_woocommmerce_hide_description_checkout_fields');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement