|
@@ 386-419 (lines=34) @@
|
| 383 |
|
/** |
| 384 |
|
* Process the delete payment method form. |
| 385 |
|
*/ |
| 386 |
|
public static function delete_payment_method_action() { |
| 387 |
|
global $wp; |
| 388 |
|
|
| 389 |
|
if ( isset( $wp->query_vars['delete-payment-method'] ) ) { |
| 390 |
|
|
| 391 |
|
$token_id = absint( $wp->query_vars['delete-payment-method'] ); |
| 392 |
|
$token = WC_Payment_Tokens::get( $token_id ); |
| 393 |
|
$delete = true; |
| 394 |
|
|
| 395 |
|
if ( is_null( $token ) ) { |
| 396 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 397 |
|
$delete = false; |
| 398 |
|
} |
| 399 |
|
|
| 400 |
|
if ( get_current_user_id() !== $token->get_user_id() ) { |
| 401 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 402 |
|
$delete = false; |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
if ( false === wp_verify_nonce( $_REQUEST['_wpnonce'], 'delete-payment-method-' . $token_id ) ) { |
| 406 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 407 |
|
$delete = false; |
| 408 |
|
} |
| 409 |
|
|
| 410 |
|
if ( $delete ) { |
| 411 |
|
WC_Payment_Tokens::delete( $token_id ); |
| 412 |
|
wc_add_notice( __( 'Payment method deleted.', 'woocommerce' ) ); |
| 413 |
|
} |
| 414 |
|
|
| 415 |
|
wp_redirect( wc_get_account_endpoint_url( 'payment-methods' ) ); |
| 416 |
|
exit(); |
| 417 |
|
} |
| 418 |
|
|
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
/** |
| 422 |
|
* Process the delete payment method form. |
|
@@ 424-457 (lines=34) @@
|
| 421 |
|
/** |
| 422 |
|
* Process the delete payment method form. |
| 423 |
|
*/ |
| 424 |
|
public static function set_default_payment_method_action() { |
| 425 |
|
global $wp; |
| 426 |
|
|
| 427 |
|
if ( isset( $wp->query_vars['set-default-payment-method'] ) ) { |
| 428 |
|
|
| 429 |
|
$token_id = absint( $wp->query_vars['set-default-payment-method'] ); |
| 430 |
|
$token = WC_Payment_Tokens::get( $token_id ); |
| 431 |
|
$delete = true; |
| 432 |
|
|
| 433 |
|
if ( is_null( $token ) ) { |
| 434 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 435 |
|
$delete = false; |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
if ( get_current_user_id() !== $token->get_user_id() ) { |
| 439 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 440 |
|
$delete = false; |
| 441 |
|
} |
| 442 |
|
|
| 443 |
|
if ( false === wp_verify_nonce( $_REQUEST['_wpnonce'], 'set-default-payment-method-' . $token_id ) ) { |
| 444 |
|
wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' ); |
| 445 |
|
$delete = false; |
| 446 |
|
} |
| 447 |
|
|
| 448 |
|
if ( $delete ) { |
| 449 |
|
WC_Payment_Tokens::set_users_default( $token->get_user_id(), intval( $token_id ) ); |
| 450 |
|
wc_add_notice( __( 'This payment method was successfully set as your default.', 'woocommerce' ) ); |
| 451 |
|
} |
| 452 |
|
|
| 453 |
|
wp_redirect( wc_get_account_endpoint_url( 'payment-methods' ) ); |
| 454 |
|
exit(); |
| 455 |
|
} |
| 456 |
|
|
| 457 |
|
} |
| 458 |
|
|
| 459 |
|
/** |
| 460 |
|
* Remove from cart/update. |