Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackeryfretty/700d8083c8755bd625ea9bac8b7d1003 to your computer and use it in GitHub Desktop.
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.
<?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