Add Logout Link To Account Menu - BigCommerce For WordPress
Jack Harner 🚀
Posted on April 22, 2019
Originally posted on Harner Designs' Blog
BigCommerce for WordPress (BC4WP) allows you to combine the power of the BigCommerce back-end with the customization of WordPress on the front-end for a truly unique E-Commerce experience.
One thing that seems missing out of their integration is a logout link on the My Account page:
It seemed like an easy fix and since I've started to dabble in making pull requests to Open Source Software, I decided to take a look. The "SubNav" as they've called it is populated in bigcommerce-for-wordpress/src/BigCommerce/Accounts/Sub_Nav.php
. It uses get_option
to pull the stored Account, Orders, & Address pages and populates the $links[]
array with the associated data.
Easy.
Just append the logout information to the $links[]
array with wp_logout_url()
and the logout link will appear in the my accounts page.
And thus, my first Pull Request to the BC4WP repo was born.
Shot Down Like A High Schooler Before Prom
My PR was rejected citing that logging out of WordPress was "Out of Scope" of the BigCommerce for WordPress plugin. However, Jonathan of Modern Tribe (the plugin developers) pointed out that there is a filter already applied to the links generated so that Site Admins can add anything they wish to that list of links: bigcommerce/account/subnav/links
.
So..? How Do You Do It?
If you're like me and want to add the logout link to the BigCommerce for WordPress Account Page Submenu, just add the following code to your theme's functions.php
file:
add_filter('bigcommerce/account/subnav/links', function ($links) {
$links[] = [
'url' => wp_logout_url(),
'label' => __('Logout', 'bigcommerce'),
'current' => false,
];
return $links;
}, 10, 1);
And that's it! Now there will be a convenient to use Logout Link on the "My Account" page with BigCommerce for WordPress.
Recent Blog Posts
Posted on April 22, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.