WooCommerce Prevent spam orders

WooCommerce Prevent spam orders

Add this code to your theme’s functions.php file or create a custom plugin.


// Hook into the WooCommerce checkout process
add_action('woocommerce_checkout_process', 'wpe_prevent_spam_orders');

function wpe_prevent_spam_orders() {
// Check if the honeypot field is empty
if (!empty($_POST['wpe_honeypot_field'])) {
wc_add_notice(__('Spam order detected. Please try again.', 'your-text-domain'), 'error');
}

// You can add additional checks here based on your requirements
// For example, checking the IP address, validating the email format, etc.
}

// Add a honeypot field to the checkout form
add_action('woocommerce_after_checkout_billing_form', 'wpe_add_honeypot_field');

function wpe_add_honeypot_field($checkout) {
echo '
<div style="display:none;"><input type="text" name="wpe_honeypot_field" id="custom_honeypot_field" autocomplete="off"></div>
';
}

// Optional: You can add more sophisticated checks based on your needs
// For example, you can check the IP address or other factors to identify spam
Με την περιήγηση σας στην ιστοσελίδα μας, αποδέχεστε τους όρους χρήσης