Recently, I found many card testing on my woocommerce site. these order all have the same characteristic, origin is Unknown. So I would like to write a some code to try to detect that if session's origin is Unknown then redirect user to homepage. My code is below, but not work. Card testing is still comming. I think maybe session's attribute (origin_attribution) is wrong but I cannot find the correct one. Anyone can help on it? Thanks.
function restrict_unknown_origin_attribution( ) {
$origin_attr = WC()->session->get('origin_attribution');
if (!empty($origin_attr) && $origin_attr == 'Unknown') {
wc_add_notice('Sorry, we do not accept orders with an unknown origin.', 'error');
wp_redirect(home_url());
exit;
}
}
add_action( 'woocommerce_checkout_process', 'restrict_unknown_origin_attribution', 10 );
Recently, I found many card testing on my woocommerce site. these order all have the same characteristic, origin is Unknown. So I would like to write a some code to try to detect that if session's origin is Unknown then redirect user to homepage. My code is below, but not work. Card testing is still comming. I think maybe session's attribute (origin_attribution) is wrong but I cannot find the correct one. Anyone can help on it? Thanks.
function restrict_unknown_origin_attribution( ) {
$origin_attr = WC()->session->get('origin_attribution');
if (!empty($origin_attr) && $origin_attr == 'Unknown') {
wc_add_notice('Sorry, we do not accept orders with an unknown origin.', 'error');
wp_redirect(home_url());
exit;
}
}
add_action( 'woocommerce_checkout_process', 'restrict_unknown_origin_attribution', 10 );
add_action('woocommerce_checkout_create_order', function($order, $data) {
if (!isset($_REQUEST['wc_order_attribution_utm_source'])) {
wc_add_notice(__('Order creation failed: Safetech Security.', 'woocommerce'), 'error');
throw new Exception('Order creation halted.');
} }, 10, 2);
This works for me
Updates the issue is in the Paypal wooocommerce plugin, I had to edit the code and stop auto-update
if (!isset($_COOKIE['sbjs_first'])) {
throw new RuntimeException(
__('Order creation failed: Origin source is required.', 'woocommerce-paypal-payments')
);
}
woocommerce-paypal-payments\modules\ppcp-button\src\Endpoint\CreateOrderEndpoint.php ... at the beginning of this function
private function create_paypal_order( \WC_Order $wc_order = null, string $payment_method = '', array $data = array() ): Order {
// Check origin source from session
if (!isset($_COOKIE['sbjs_first'])) {
throw new RuntimeException(
__('Order creation failed: Origin source is required.', 'woocommerce-paypal-payments')
);
}
assert( $this->purchase_unit instanceof PurchaseUnit );