Home > database >  How to add the payment-methods endpoint to the account navigation in Woocommerce?
How to add the payment-methods endpoint to the account navigation in Woocommerce?

Time:10-19

I want to add a a link to the payment-methods page so that a logged in user easily can change method. Or add one.

I have set up the correct hook, where i'm doing some other stuff, but cant figure out how to proceed?

  add_filter('woocommerce_account_menu_items', array($this, 'shorty_account_menu_items'), 10, 1);

  function shorty_account_menu_items($items) {
    $items['edit-account'] = 'Settings';
    $items['orders'] = 'My History';
    unset($items['dashboard']);
    return $items;
  }

CodePudding user response:

The filter hook you are using is correct. To display a link to payment methods page, push the endpoint into the $items array and output the entire array.

Usage:

add_filter('woocommerce_account_menu_items', 'shorty_account_menu_items');

  function shorty_account_menu_items($items) {
    $items['payment-methods']='Payment Methods';
    return $items;
  }

You can also move the payment-methods link to appear above the logout link using this snippet:

add_filter('woocommerce_account_menu_items', function($items) {
    $logout = $items['customer-logout'];
    unset($items['customer-logout']);
    $items['payment-methods'] = "Payment Methods";
    $items['customer-logout'] = $logout;
    return $items;
});

  • Related