WC_Form_Handler::delete_payment_method_action()public staticWC 1.0

Process the delete payment method form.

Method of the class: WC_Form_Handler{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Form_Handler::delete_payment_method_action();

WC_Form_Handler::delete_payment_method_action() code WC 8.7.0

public static function delete_payment_method_action() {
	global $wp;

	if ( isset( $wp->query_vars['delete-payment-method'] ) ) {
		wc_nocache_headers();

		$token_id = absint( $wp->query_vars['delete-payment-method'] );
		$token    = WC_Payment_Tokens::get( $token_id );

		if ( is_null( $token ) || get_current_user_id() !== $token->get_user_id() || ! isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'delete-payment-method-' . $token_id ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
			wc_add_notice( __( 'Invalid payment method.', 'woocommerce' ), 'error' );
		} else {
			WC_Payment_Tokens::delete( $token_id );
			wc_add_notice( __( 'Payment method deleted.', 'woocommerce' ) );
		}

		wp_safe_redirect( wc_get_account_endpoint_url( 'payment-methods' ) );
		exit();
	}

}