BrianHenryIE / bh-wc-checkout-rate-limiter

Prevent card-attack fraud on WooCommerce stores by rate-limiting the "place order" button
GNU General Public License v2.0
57 stars 4 forks source link

Additional hooks #20

Open capuderg opened 1 year ago

capuderg commented 1 year ago

Thank you for creating this plugin! 🙏

We are using the CheckoutWC plugin and it does not use the wc_ajax_checkout hook, so your rate limiting is not triggered/checked.

We modified your plugin, to use it on our site, but would prefer some additional hooks that we can use and extend its functionality, so we can update your plugin regularly.

Action hook 1: Here https://github.com/BrianHenryIE/bh-wc-checkout-rate-limiter/blob/master/src/class-bh-wc-checkout-rate-limiter.php#L97, we would need an additional action hook, so we can hook the CheckoutWC ajax hook to your rate limiter. We added this line: add_action( 'cfw_before_process_checkout', array( $ajax, 'rate_limit_checkout' ), 0 );, so we would need an action hook, like do_action( 'bh_wcr_define_woocommerce_ajax_hooks', $ajax ); in that method.

Action hook2: Here https://github.com/BrianHenryIE/bh-wc-checkout-rate-limiter/blob/master/src/woocommerce/class-ajax.php#L113, right before the json error response, we would need another action item, because CheckoutWC is expecting a different response, so adding an action hook like this would be awesome: do_action( 'bh_wcr_checkout_rate_limit_exceeded', $rate_limiter );

I'll prepare a quick PR so it will be easier for you, but I don't know which prefix to use for these hooks, because I can see mixed ones being used in the plugin.