Created
May 25, 2022 21:03
-
-
Save dustinleer/24bcd8faedb4ec7eb01ad0391bee759d to your computer and use it in GitHub Desktop.
Add a custom WooCommerce My Account endpoint
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
<?php | |
/** | |
* Add endpoint rewrite. | |
*/ | |
function ip_custom_endpoint() { | |
add_rewrite_endpoint( 'edit-wishlists', EP_ROOT | EP_PAGES ); | |
} | |
add_action( 'init', 'ip_custom_endpoint', 10, 1 ); | |
/** | |
* Insert the new endpoint into the My Account menu. | |
* | |
* @param array $items | |
* @return array | |
*/ | |
function ip_new_menu_items( $items ) { | |
$items[ 'edit-wishlists' ] = __( 'Wishlists', 'ip_master' ); | |
return $items; | |
} | |
add_filter( 'woocommerce_account_menu_items', 'ip_new_menu_items', 10, 1 ); | |
$endpoint = 'edit-wishlists'; | |
/** | |
* Insert the new endpoint content into the My Account area. | |
*/ | |
function ip_endpoint_content() { | |
echo '<div id="wl-wrapper" class="woocommerce">'; | |
echo '<h2>Wishlists</h2>'; | |
echo get_template_part( 'wishlist-manage' ); | |
echo '</div>'; | |
} | |
add_action( 'woocommerce_account_' . $endpoint . '_endpoint', 'ip_endpoint_content', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment