I've seen loads of example of how to re-order / change the navigation and page with the WooCommerce my account dashboard. But i can't for the life of me work out how to change the main titles for each section (My Account, Orders, Downloads, Addresses etc).
I've searched through the templates but no joy. I've tried using conditional php comments to echo the titles for the correct page. But it doesn't work because my account section uses endpoints. I've tried adding a filter, but no joy. Anyone got any idea how i change these titles?
Thanks
It can be done using the composite filter hook woocommerce_endpoint_{$endpoint}_title.
For example if you need to change the My Account "** Account details**" title you will use (where the endpoint is edit-account):
add_filter( 'woocommerce_endpoint_edit-account_title', 'change_my_account_edit_account_title', 10, 2 );
function change_my_account_edit_account_title( $title, $endpoint ) {
$title = __( "Edit your account details", "woocommerce" );
return $title;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Found I can do using woo_endpoint_title filter.
This worked for me to rename the titles of all my account pages:
function wpb_woo_endpoint_title( $title, $id ) {
if ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
$title = "Deine Buchungen";
}
elseif ( is_wc_endpoint_url( 'edit-address' ) && in_the_loop() ) {
$title = "Deine Rechnungs- & Behandlungsadresse";
}
elseif ( is_wc_endpoint_url( 'payment-methods' ) && in_the_loop() ) {
$title = "Deine Bezahlmethoden";
}
elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
$title = "Dein Nutzerkonto";
}
return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );
Related
the question is just on the title, but well here's the problem i tried this code on my function.php which at first works fine, but suddenly i realized that the menus on footer changed to be the same as the header menus.
here is the code :
function wpc_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-out';
} else {
$args['menu'] = 'Main Menu';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
What i want is to have a different header menus for user when they log in and log out, but the footer menus stays the same. i am currently learning how to add the conditional logic on the functions.php atm, but if there are other ways please let me know, thx in advance
Probably a bit late for a reply but I just did this in the Astra theme today, so thought I would share the know-how for others who might need it. It can easily be adjusted for any WordPress theme actually:
You can check the location of the menu and only change the menu in the location(s) you decide (in this example 'primary' and 'mobile_menu' which is what Astra theme calls the the main nav locations for desktop and mobile) :
function custom_wp_nav_menu_args( $args = '' ) {
if( $args['theme_location'] == 'primary' || $args['theme_location'] == 'mobile_menu' ) {
if( ! is_user_logged_in() ) {
$args['menu'] = 'logged-out';
}
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'custom_wp_nav_menu_args' );
If you dont want to use the explicit position of the menu (in my case the nav was in a widget in the footer and not a set theme location), you can also do the same thing by using the id, name or slug of the menu. For example if you want to change the menu 'test-menu' for 'test-menu-logged-out' if the user is logged out, you can use this:
function custom_2_wp_nav_menu_args ( $args = '' ) {
$menu_slug = $args['menu']->slug;
if ( ! is_user_logged_in() && $menu_slug == 'test-menu' ){
$args['menu'] = 'test-menu-logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'custom_2_wp_nav_menu_args' );
Attempting to change the title of the "pay for order" page / "customer payment page"
https://url.com/checkout/order-pay/753/?pay_for_order=true&key=wc_order_xxxxxx
Below is not currently working, it is modified from changing the title on the thank you page.
add_filter( 'the_title', 'woo_title_pay_order', 10, 2 );
function woo_title_pay_order( $title, $id ) {
if ( function_exists( 'is_pay_for_order_page' ) &&
is_pay_for_order_page() && get_the_ID() === $id ) {
$title = "Checkout";
}
return $title;
}
Updated
You can use the following to change "Pay for order" page title:
add_filter( 'the_title', 'change_pay_for_order_title' );
function change_pay_for_order_title( $title ) {
if ( is_wc_endpoint_url( 'order-pay' ) ) {
return __('Checkout', 'woocommerce');
}
return $title;
}
Or also the following code based on 'order-pay' endpoint (but changes the breadcrumb):
add_filter( 'woocommerce_endpoint_order-pay_title', 'change_checkout_order_pay_title' );
function change_checkout_order_pay_title( $title ) {
return __( "Checkout", "woocommerce" );
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related: Set My Account custom items endpoints titles in WooCommerce
After Allow guest checkout for specific products only in WooCommerce answer to my previous question, the following code redirect users to login page:
add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access');
function checkout_redirect_non_logged_to_login_access() {
if( is_checkout() && !is_user_logged_in()){
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
exit;
}
}
But I have some products which allows guest checkout (see the linked question/answer above). So how could I fix my code for the products which allows guest checkout to disable that code redirection?
You can replace my previous answer code with the following:
// Custom conditional function that checks if checkout registration is required
function is_checkout_registration_required() {
if ( ! WC()->cart->is_empty() ) {
// Loop through cart items
foreach ( WC()->cart->get_cart() as $item ) {
// Check if there is any item in cart that has not the option "Guest checkout allowed"
if ( get_post_meta( $item['product_id'], '_allow_guest_checkout', true ) !== 'yes' ) {
return true; // Found: Force checkout user registration and exit
}
}
}
return false;
}
add_filter( 'woocommerce_checkout_registration_required', 'change_tax_class_user_role', 900 );
function change_tax_class_user_role( $registration_required ) {
return is_checkout_registration_required();
}
Then your current question code will be instead:
add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access');
function checkout_redirect_non_logged_to_login_access() {
if( is_checkout() && !is_user_logged_in() && is_checkout_registration_required() ){
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
exit;
}
}
Code goes in functions.php file of your active child theme (or active theme). It should works.
I am trying to figure out how to replace "woocommerce_page_title" with an ACF field? If there isn't one then it should fall back to "woocommerce_page_title();". I can't seem to find anything super helpful. Your help would be greatly appreciated.
add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $title ) {
$title = get_field("custom_tag_h1");
return $title;
}
For Archives pages taxonomy titles and ACF:
The woocommerce_page_title works for shop page and taxonomy archive pages, so in ACF:
Then in a product category for example (here "Clothing"), you set your custom title:
In the code, you need to get the queried object (the WP_Term object) for the taxonomy archive pages and to set it as following:
add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $page_title ) {
if ( ! function_exists('get_field') || is_search() )
return $page_title;
if ( is_tax() ) {
$term = get_queried_object();
$the_id = $term->taxonomy . '_' . $term->term_id;
} elseif ( is_shop() ) {
$the_id = wc_get_page_id( 'shop' );
}
return get_field( "custom_tag_h1", $the_id ) ? get_field( "custom_tag_h1", $the_id ) : $page_title;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
I am currently using Wordpress Version 4.9.8 and enabled Woocommerce plugin. I need to rename the tab name "Dashboard" to "My Rewards" in My account pages.
I found the code below, but it doesn't seem to be working:
function wpb_woo_endpoint_title( $title, $id ) {
if ( is_wc_endpoint_url( 'dashboard' ) && in_the_loop() ) { // add your endpoint urls
$title = "My Rewards"; // change your entry-title
return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );
Any help is appreciated.
Try the following instead (Works in Woocommerce since version 2.6):
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items', 22, 1 );
function custom_my_account_menu_items( $items ) {
$items['dashboard'] = __("My Rewards", "woocommerce");
return $items;
}
This code goes in function.php file of your active child theme (or active theme). Tested and works.