/**
  * Process the delete payment method form.
  */
 public static function set_default_payment_method_action()
 {
     global $wp;
     if (isset($wp->query_vars['set-default-payment-method'])) {
         $token_id = absint($wp->query_vars['set-default-payment-method']);
         $token = WC_Payment_Tokens::get($token_id);
         $delete = true;
         if (is_null($token)) {
             wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error');
             $delete = false;
         }
         if (get_current_user_id() !== $token->get_user_id()) {
             wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error');
             $delete = false;
         }
         if (false === wp_verify_nonce($_REQUEST['_wpnonce'], 'set-default-payment-method-' . $token_id)) {
             wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error');
             $delete = false;
         }
         if ($delete) {
             WC_Payment_Tokens::set_users_default($token->get_user_id(), intval($token_id));
             wc_add_notice(__('This payment method was successfully set as your default.', 'woocommerce'));
         }
         wp_redirect(wc_get_account_endpoint_url('payment-methods'));
         exit;
     }
 }
 /**
  * Entry method for the Add Payment Method feature flow. Note this is *not*
  * stubbed in the WC_Payment_Gateway abstract class, but is called if the
  * gateway declares support for it.
  *
  * @since 4.0.0
  */
 public function add_payment_method()
 {
     assert($this->supports_add_payment_method());
     $order = $this->get_order_for_add_payment_method();
     try {
         $result = $this->do_add_payment_method_transaction($order);
     } catch (SV_WC_Plugin_Exception $e) {
         $result = array('message' => sprintf(esc_html__('Oops, adding your new payment method failed: %s', 'woocommerce-plugin-framework'), $e->getMessage()), 'success' => false);
     }
     SV_WC_Helper::wc_add_notice($result['message'], $result['success'] ? 'success' : 'error');
     // if successful, redirect to the newly added method
     if ($result['success']) {
         // if this is WooCommerce 2.5.5 or older, redirect to the My Account page
         if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
             $redirect_url = wc_get_page_permalink('myaccount');
             // otherwise, redirect to the Payment Methods page (WC 2.6+)
         } else {
             $redirect_url = wc_get_account_endpoint_url('payment-methods');
         }
         // otherwise, back to the Add Payment Method page
     } else {
         $redirect_url = wc_get_endpoint_url('add-payment-method');
     }
     wp_safe_redirect($redirect_url);
     exit;
 }
示例#3
0
if (!defined('ABSPATH')) {
    exit;
}
do_action('woocommerce_before_account_navigation');
?>

<nav class="woocommerce-MyAccount-navigation">
	<ul>
		<?php 
foreach (wc_get_account_menu_items() as $endpoint => $label) {
    ?>
			<li class="<?php 
    echo wc_get_account_menu_item_classes($endpoint);
    ?>
">
				<a href="<?php 
    echo esc_url(wc_get_account_endpoint_url($endpoint));
    ?>
"><?php 
    echo esc_html($label);
    ?>
</a>
			</li>
		<?php 
}
?>
	</ul>
</nav>

<?php 
do_action('woocommerce_after_account_navigation');
 /**
  * Redirect back to the Payment Methods (WC 2.6+) or My Account page
  *
  * @since 4.0.0
  */
 protected function redirect_to_my_account()
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_lt_2_6()) {
         $url = wc_get_page_permalink('myaccount');
     } else {
         $url = wc_get_account_endpoint_url('payment-methods');
     }
     wp_redirect($url);
     exit;
 }