Skip to content

Instantly share code, notes, and snippets.

@vanbo
Created August 16, 2023 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/f7691a8dd977558afb75f98c7f7253c8 to your computer and use it in GitHub Desktop.
Save vanbo/f7691a8dd977558afb75f98c7f7253c8 to your computer and use it in GitHub Desktop.
pay360-register-all-users
/**
* NOTE: Add to 'wp-content/themes/your-theme/functions.php' file
*/
add_filter( 'pay360_hosted_cashier_get_parameters', 'vanbodevelops_pay360_always_register_account', 10, 3 );
function vanbodevelops_pay360_always_register_account( $args, $order, $gateway ) {
if ( 0 < $order->get_customer_id() ) {
return $args;
}
$customer_id = $order->get_meta( 'wc_pay360_guest_customer_id', true );
if ( ! $customer_id ) {
$customer_id = vanbodevelops_get_guest_merchant_customer_id( $gateway );
}
$args['customer']['registered'] = true;
$args['customer']['identity']['merchantCustomerId'] = $customer_id;
return $args;
}
function vanbodevelops_get_guest_merchant_customer_id( $gateway ) {
return str_replace( array( ' ' ), array( '-' ), $gateway->get_option( 'cashier_customer_prefix' ) ) . uniqid() . vanbodevelops_get_guest_customers_suffix();
}
function vanbodevelops_get_guest_customers_suffix() {
$suffix = (int) get_option( 'wc_pay360_guest_customers_suffix', 0 );
$suffix = $suffix + 1;
update_option( 'wc_pay360_guest_customers_suffix', $suffix );
return $suffix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment