Created
February 20, 2018 16:26
-
-
Save hirejordansmith/6e19528dd77a1585d92c46c7ac3b4390 to your computer and use it in GitHub Desktop.
Add New Tab to the WooCommerce My Account Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @snippet Add New Tab to WooCommerce My Account Page | |
* @author Hire Jordan Smith // https://hirejordansmith.com | |
*/ | |
// Register new endpoint to use for My Account page | |
add_action( 'init', 'hjs_add_account_update_endpoint' ); | |
function hjs_add_account_update_endpoint() { | |
add_rewrite_endpoint( 'account-update', EP_ROOT | EP_PAGES ); | |
} | |
// Add new query var | |
add_filter( 'query_vars', 'hjs_account_update_query_vars', 0 ); | |
function hjs_account_update_query_vars( $vars ) { | |
$vars[] = 'account-update'; | |
return $vars; | |
} | |
// Insert the new endpoint into the My Account menu | |
add_filter( 'woocommerce_account_menu_items', 'hjs_add_account_update_link_my_account' ); | |
function hjs_add_account_update_link_my_account( $items ) { | |
$items['account-update'] = 'Account Details'; | |
return $items; | |
} | |
// Add content to the new endpoint | |
add_action( 'woocommerce_account_account-update_endpoint', 'hjs_account_update_content' ); | |
function hjs_account_update_content() { | |
echo '<h3>Account Details</h3>'; | |
echo do_shortcode('[gravityform id="3" title="false" description="false" ajax="true" tabindex="-1"]'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment