Site logo

Archived topic

Can I change the default opened tab depending on the link/?

10 replies · Started by Jusung on February 24, 2023

Viewing posts 1–11 of 11

When it is a certain link, can I change the opened tab link?

by default, I open the first tap, but when It is from other link, I want to open the second tab.

Hi there,

if you select the Tab Item, and in Advanced add a unique HTML Anchor. For example tab-2

Then when you can use that Jump Link, eg. https://mywebsite.com/page-slug/#tab-2 and that link will jump to and open that tab.

Hello.

I can't understand.
I tried to add it as you said, but nothing happened.

When the link is from those, I want to open third tap.

Then what can I add?
Is it possible to add 2 html anchor?
I tried to add billing, but nothing happened.

maybe I can use "edit-address" this one??

Those URLs are for an account page, i would need a login for them

I added the ID and PW.

On third tap, when I click edit, the link includes “edit-address” this one.

See here:

https://www.screencast.com/t/71VFIeEp

In the Tab Item -> Advanced --> HTML Anchor i add my anchor: my-anchor

Now i got to: https://mysite.com/page-name/#my-anchor

And that URL will take me to and open that Tab.

You will need to just the Jumplink methods instead of the standard Woocomerce URLs as you have relaced their tabs with your own

I understand now.

So, I added the html anchor like test111
and after that, I have to add #test111 at the end of the link.

For woocommerce, I need to change the end point using php code..
Is this right?

// Change the edit billing address link
add_filter( 'woocommerce_billing_fields', 'my_custom_billing_fields' );
function my_custom_billing_fields( $fields ) {
    $fields['billing_address_1']['custom_link'] = wc_get_account_endpoint_url( 'edit-address', 'billing' ) . 'https://abc/my-account/edit-address/billing/#address-tab';
    return $fields;
}

// Change the edit shipping address link
add_filter( 'woocommerce_shipping_fields', 'my_custom_shipping_fields' );
function my_custom_shipping_fields( $fields ) {
    $fields['shipping_address_1']['custom_link'] = wc_get_account_endpoint_url( 'edit-address', 'shipping' ) . 'https://abc/my-account/edit-address/shipping/#address-tab';
    return $fields;
}

// Replace the link in the billing address template
add_filter( 'woocommerce_my_account_edit_address_url', 'my_custom_edit_billing_address_link', 10, 3 );
function my_custom_edit_billing_address_link( $url, $type, $id ) {
    if ( $type == 'billing' ) {
        $url = wc_get_account_endpoint_url( 'edit-address', 'billing' ) . 'https://abc.com/my-account/edit-address/billing/#address-tab';
    }
    return $url;
}

// Replace the link in the shipping address template
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'my_custom_shipping_address_link', 10, 3 );
function my_custom_shipping_address_link( $address, $customer_id, $address_id ) {
    $address['edit']['url'] = wc_get_account_endpoint_url( 'edit-address', 'shipping' ) . 'https://abc.com/my-account/edit-address/shipping/#address-tab';
    return $address;
}

These are the link I used, but doen's make any change.

Try URL:

https://abc.com/my-account/edit-address/#address-tab

As all endpoints are simply a query var.
But you're hacking the way Woocommerce works, so i cannot really advise on this, as you could make bigger problems doing this, and we cannot support Woocommrce custom development

Thank you for help !!

You're welcome

This archived topic is closed to new replies.