Forked from sandeshjangam/woocommerce-add-new-tab-my-account-page.php
Created
June 23, 2020 10:56
-
-
Save cristianstan/324ea3b464f90a136e7c1c1d445d109e to your computer and use it in GitHub Desktop.
WooCommerce - Add New “Tab” at My Account Page
This file contains hidden or 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
<?php | |
/** | |
* @snippet WooCommerce How To Add New Tab @ My Account | |
* @how-to Watch tutorial @ https://techiesandesh.com | |
* @author Sandesh Jangam | |
* @compatible WooCommerce 3.6.2 | |
* @donate $7 https://www.paypal.me/SandeshJangam/7 | |
*/ | |
/** | |
* 1. Register new endpoint slug to use for My Account page | |
*/ | |
/** | |
* @important-note Resave Permalinks or it will give 404 error | |
*/ | |
function ts_custom_add_premium_support_endpoint() { | |
add_rewrite_endpoint( 'premium-support', EP_ROOT | EP_PAGES ); | |
} | |
add_action( 'init', 'ts_custom_add_premium_support_endpoint' ); | |
/** | |
* 2. Add new query var | |
*/ | |
function ts_custom_premium_support_query_vars( $vars ) { | |
$vars[] = 'premium-support'; | |
return $vars; | |
} | |
add_filter( 'woocommerce_get_query_vars', 'ts_custom_premium_support_query_vars', 0 ); | |
/** | |
* 3. Insert the new endpoint into the My Account menu | |
*/ | |
function ts_custom_add_premium_support_link_my_account( $items ) { | |
$items['premium-support'] = 'Premium Support'; | |
return $items; | |
} | |
add_filter( 'woocommerce_account_menu_items', 'ts_custom_add_premium_support_link_my_account' ); | |
/** | |
* 4. Add content to the new endpoint | |
*/ | |
function ts_custom_premium_support_content() { | |
echo '<h3>Premium WooCommerce Support</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>'; | |
echo do_shortcode( ' /* your shortcode here */ ' ); | |
} | |
/** | |
* @important-note "add_action" must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format | |
*/ | |
add_action( 'woocommerce_account_premium-support_endpoint', 'ts_custom_premium_support_content' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment