Last active
December 18, 2024 18:56
-
-
Save zackeryfretty/700d8083c8755bd625ea9bac8b7d1003 to your computer and use it in GitHub Desktop.
Redirects any traffic to the WooCommerce '/wc/store/checkout' endpoint back to the homepage and logs the attempt in the error_log for review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function zf_block_and_log_checkout_api_requests() { | |
$current_url = $_SERVER['REQUEST_URI']; | |
$msg_to_log = 'Checkout API Blocked: ' . $_SERVER['REMOTE_ADDR']; | |
if ( strpos( $current_url, '/wp-json/wc/store/checkout' ) !== false ) { | |
error_log( $msg_to_log , 0); | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} | |
add_action('rest_api_init', 'zf_block_and_log_checkout_api_requests'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment