Search code examples
phpwoocommerceshortcode

Woocommerce Shortcode for edit and add Shipping Address


I am trying to render a portion of the Woocommerce - My Account section. Specifically the form for editing or adding a Shipping Address (myaccount/form-edit-address.php). By default the Shortcode I created shows the Billing Address. I can't figure out how to pass a variable or specify that I want the Shipping Address part of the code.

This is the Shortcode for the Billing Address:

add_shortcode('edit_address', 'display_myaccount_edit_address');
function display_myaccount_edit_address()
{
    return WC_Shortcode_My_Account::edit_address();
}

And I am trying to achieve it doing this (it doesn't work obviously)

add_shortcode('edit_address_shipping', 'display_myaccount_edit_address_shipping');
function display_myaccount_edit_address_shipping()
{
    return WC_Shortcode_My_Account::edit_address_shipping($load_address = 'Shipping address');
}

Any idea how to do it? Any help would be pretty much appreciated!


Solution

  • According to the documentation, the key to pass is 'shipping': So the function for shortcode will look like this:

        function display_myaccount_edit_address_shipping()
        {
            return WC_Shortcode_My_Account::edit_address_shipping('shipping');
        }
    
        add_shortcode('edit_address_shipping', 'display_myaccount_edit_address_shipping');
    

    https://woocommerce.wp-a2z.org/oik_api/wc_shortcode_my_accountedit_address/