Skip to content

Commit a8a6fe7

Browse files
authored
Reset Widget on WooCommerce error (#163)
* reset widget on woocommerce error * use jquery for handling checkout_error event
1 parent 4fb0aeb commit a8a6fe7

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
jQuery(function ($) {
2+
function resetWidgets() {
3+
if (window.frcaptcha) {
4+
window.frcaptcha.widgets.forEach((c) => c.reset());
5+
} else if (window.friendlyChallenge) {
6+
window.friendlyChallenge.autoWidget.reset();
7+
}
8+
}
9+
10+
$(document.body).on("checkout_error", function () {
11+
console.log("checkout_error jQuery");
12+
resetWidgets();
13+
});
14+
});

friendly-captcha/modules/woocommerce/woocommerce_checkout.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function frcaptcha_wc_checkout_show_widget()
1515
echo '<style>.frc-captcha {max-width:100%; margin-bottom: 1em}</style>';
1616

1717
frcaptcha_enqueue_widget_scripts();
18+
wp_enqueue_script(
19+
'frcaptcha_wc-friendly-captcha',
20+
plugin_dir_url(__FILE__) . 'script.js',
21+
array('friendly-captcha-widget-module', 'friendly-captcha-widget-fallback'),
22+
FriendlyCaptcha_Plugin::$version,
23+
true
24+
);
1825
}
1926

2027
add_action('woocommerce_checkout_process', 'frcaptcha_wc_checkout_validate', 20, 3);

friendly-captcha/modules/woocommerce/woocommerce_login.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function frcaptcha_wc_login_show_widget()
1515
echo '<style>.frc-captcha {max-width:100%; margin-bottom: 1em}</style>';
1616

1717
frcaptcha_enqueue_widget_scripts();
18+
wp_enqueue_script(
19+
'frcaptcha_wc-friendly-captcha',
20+
plugin_dir_url(__FILE__) . 'script.js',
21+
array('friendly-captcha-widget-module', 'friendly-captcha-widget-fallback'),
22+
FriendlyCaptcha_Plugin::$version,
23+
true
24+
);
1825
}
1926

2027
add_action('woocommerce_process_login_errors', 'frcaptcha_wc_login_validate', 20, 3);

friendly-captcha/modules/woocommerce/woocommerce_lost_password.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ function frcaptcha_wc_lost_password_show_widget()
1515
echo '<style>.frc-captcha {max-width:100%; margin-bottom: 1em}</style>';
1616

1717
frcaptcha_enqueue_widget_scripts();
18+
wp_enqueue_script(
19+
'frcaptcha_wc-friendly-captcha',
20+
plugin_dir_url(__FILE__) . 'script.js',
21+
array('friendly-captcha-widget-module', 'friendly-captcha-widget-fallback'),
22+
FriendlyCaptcha_Plugin::$version,
23+
true
24+
);
1825
}

friendly-captcha/modules/woocommerce/woocommerce_register.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function frcaptcha_wc_register_show_widget()
1515
echo '<style>.frc-captcha {max-width:100%; margin-bottom: 1em}</style>';
1616

1717
frcaptcha_enqueue_widget_scripts();
18+
wp_enqueue_script(
19+
'frcaptcha_wc-friendly-captcha',
20+
plugin_dir_url(__FILE__) . 'script.js',
21+
array('friendly-captcha-widget-module', 'friendly-captcha-widget-fallback'),
22+
FriendlyCaptcha_Plugin::$version,
23+
true
24+
);
1825
}
1926

2027
add_action('woocommerce_process_registration_errors', 'frcaptcha_wc_register_validate', 20, 3);

0 commit comments

Comments
 (0)