woocommerce offtopic - How to block checkout process when session origin is unknown?

admin2025-01-07  5

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 );
Share Improve this question asked Dec 3, 2024 at 2:42 VinceVince 211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0
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 );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263083a863.html

最新回复(0)