I am working with woo-commerce user dashboard template.
I need to print the title of current endpoint instead of the_title();
.
following image snapshot of
DOMIAN.com/my-account/orders/. there should be page title as "My Order" but it's "My Account".
Same requirement for other endpoint titles too.
Please help me out.
The original order of the My Account menu items can be seen in /wp-content/plugins/woocommerce/includes/wc-account-functions.php
/**
* Get My Account menu items.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_menu_items() {
return apply_filters( 'woocommerce_account_menu_items', array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => __( 'Addresses', 'woocommerce' ),
'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
'edit-account' => __( 'Account Details', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
) );
}
You can change the order of these endpoints by using the woocommerce_account_menu_items filter, you can also change the list item title with the same filter.
<?php
function wpb_woo_my_account_order() {
$myorder = array(
'my-custom-endpoint' => __( 'My Stuff', 'woocommerce' ),
'edit-account' => __( 'Change My Details', 'woocommerce' ),
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Download MP4s', 'woocommerce' ),
'edit-address' => __( 'Addresses', 'woocommerce' ),
'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
);
return $myorder;
}
add_filter ( 'woocommerce_account_menu_items', 'wpb_woo_my_account_order' );
One of the limitations with changing the list item title is that it won’t change the entry-title.
One way around changing the entry-title of the WooCommerce custom endpoint is to use the_title filter with the in_the_loop conditional.
<?php
/*
* Change the entry title of the endpoints that appear in My Account Page - WooCommerce 2.6
* Using the_title filter
*/
function wpb_woo_endpoint_title( $title, $id ) {
if ( is_wc_endpoint_url( 'downloads' ) && in_the_loop() ) { // add your endpoint urls
$title = "Download MP3s"; // change your entry-title
}
elseif ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
$title = "My Orders";
}
elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
$title = "Change My Details";
}
return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );