0
votes

I'm trying to create a tabbed version of "My Account" in woocommerce. I have built my pages in php using bootstrap css and included the wordpress header and footer so the page loads correctly. The tabs display as expected by I am having an issue with the endpoint urls in woocommerce:

- 'edit-address'

- 'view-order'

These endpoints are generated dynamically and appended to the url: www.site-name.com/my-account/edit-address Here's the function call (in file .plugins/woocommerce/myaccount/form-edit-address.php):

<a href="<?php echo wc_get_endpoint_url( 'edit-address', $name  ); ?>

I've included 'my-addresses' in my tabbed page which dispays ok. However, the link to edit the shipping and billing addresses is generated by the above call to the endpoints. When the link is clicked the page fails to load and returns a 404 error.

My custom php page is basically www.site-name.com/account/edit-address

The problem is:

  • The 'edit-address' page content is not loading and I get a 404 error

I'm guessing the issue is caused because my pages are external php pages and not stored with wp database?

Is there a way I can customise the endpoint url so it appends correctly and loads the page?

Link to the page on my site: www.thecookerytutor dot co dot uk/account

Origional woocommerce my-account page: www.thecookerytutor dot co dot uk/my-account (You will need to create a login to view both pages)

It's had me stumped for days! Thanks in advance.

Code for my addresses tab on my custom php page as promised...

echo "<div id = 'edit-addresses' class='tab-pane fade'>";
                echo "<div id = 'content' class = 'page col-full'>";
                echo "<section id = 'main' class = 'col-left'>";
                echo "<BR>";
                        include "my-address.php";
                echo "</section>";
            echo "</div>";
     echo "</div>";`

As you can see I'm including the wc page that loads the addresses (I've copied to the local folder) Here's the content of edit-address.php (I've copied to my local folder and added wp header). The page loads the header but the get address function fails at line 50.

<?php 

define('WP_USE_THEMES', false); 

require('../wp-blog-header.php');

add_filter( 'wp_title', 'wp_title_so_18381106', 10, 3 );
function wp_title_so_18381106( $title, $sep, $seplocation ) 
{
  return 'Your Account | ';
}

get_header();
?>
<?php
/**
 * Edit address form
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $current_user;

$page_title = ( $load_address === 'billing' ) ? __( 'Billing Address', 'woocommerce' ) : __( 'Shipping Address', 'woocommerce' );

get_currentuserinfo();

?>

<?php wc_print_notices(); ?>

<?php //if ( ! $load_address ) : ?>

    <?php //wc_get_template( 'myaccount/my-address.php' ); ?>

<?php //else : ?>
    <form method="post">

        <h3><?php echo apply_filters( 'woocommerce_my_account_edit_address_title', $page_title ); ?></h3>

        <?php do_action( "woocommerce_before_edit_address_form_{$load_address}" ); ?>

/fails to load here/

<?php foreach ( $address as $key => $field ) : ?>

                <?php woocommerce_form_field( $key, $field, ! empty( $_POST[ $key ] ) ? wc_clean( $_POST[ $key ] ) : $field['value'] ); ?>

            <?php endforeach; ?>

            <?php do_action( "woocommerce_after_edit_address_form_{$load_address}" ); ?>

            <p>
                <input type="submit" class="button" name="save_address" value="<?php _e( 'Save Address', 'woocommerce' ); ?>" />
                <?php wp_nonce_field( 'woocommerce-edit_address' ); ?>
                <input type="hidden" name="action" value="edit_address" />
            </p>

        </form>

    <?php //endif; ?> 
1
what url are you getting? and what should have been the correct url?Reigel
The url is now appending correctly: www.site-name.com/account/edit-address/billing but I still get a 404 error.jmiller
so there's no problem now?Reigel
not loading content for 'edit-address'...404 error i've amended my questionjmiller
try visiting your permalink settings page.. in the admin dashboard, visit Settings > Permalinks. Just view it, then check if you still get 404 on your edit-addressReigel

1 Answers

0
votes

WooCommerce is a plugin for WordPress, you can't use it without WordPress... for example /my-account/edit-address/, that my-account is actually the page you are rendering and edit-address is just a variable. edit-address was added as an endpoint to my-account. you need to do the same for your account.

You should get an idea of what endpoints are.

Other thoughts about this. If you really want to use account and not my-account, look into your pages for "My Account" and change it's permalink. You can also create another page that can use account in it's permalink. Then use that page in your WooCommerce > Settings > Account tab > My Account Page.

If you have some custom php codes, you can just copy the template from your woocommerce plugin to your theme folder and edit the file you need. Read Template Structure + Overriding Templates via a Theme.

And if I have not addressed your problem, comment down below.