Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Support Rynald0s.a11n

    (@rynald0s)

    Automattic Happiness Engineer

    Thread Starter s31concierge

    (@s31concierge)

    Many thanks for this, I read through it and think I can do it on my own, but I wanted to ask… Do the snippets from the guide get pasted in my-account.php?

    Is there a guide or discussion that might be a bit more for beginners?

    Best not to edit my-account.php.

    Those snippets would go in functions.php for your child theme. Here’s how to make a child theme:
    https://codex.wordpress.org/Child_Themes

    Alternatively, perhaps not as good, you can try a code snippets plugin:
    https://wordpress.org/plugins/code-snippets/

    PHP is explained here:
    https://www.w3schools.com/php/
    You can google individual issues. Unfortunately there seems to always be more than one approach to any particular problem.

    What you are proposing is not really a starter project. If you get stuck, you can post a job:
    https://jobs.wordpress.net/

    Thread Starter s31concierge

    (@s31concierge)

    I created a child theme and added the snippet for creating new endpoints to the Child theme’s functions.php file. I also added the snippet for flushing rewrite rules to it (the theme version, not the plugin version)

    I successfully added a new endpoint and it now showing up in My Account.

    I now need a bit of help adding the custom content to the new tab.
    The new content will be the booking history of my customers as seen here: https://dev.school31lofts.com/my-bookings/

    How can I embed this content in the new endpoint?

    Thanks

    My endpoint is “warranties”, so:

    add_action( 'woocommerce_account_warranties_endpoint', 'tm_warranties_content' );
    function tm_warranties_content() {
      print '.....';
    }
    Thread Starter s31concierge

    (@s31concierge)

    Thank you!
    So I have the content linked, but it’s not opening the content within the dashboard (with other tabs visible) but rather just linking the the /my-bookings page.
    What is the function that will properly load the content in the dashboard?
    Many thanks in advance!

    Probably missed a step. Don’t forget to resave permalinks (twice is recommeded by some)

      register_activation_hook( __FILE__, 'tm_flush_rewrite_rules' );
      function tm_flush_rewrite_rules() {
        add_rewrite_endpoint( 'warranties', EP_ROOT | EP_PAGES );
        flush_rewrite_rules();
      } // end function
    
      // register new endpoint to use for My Account page
      add_action( 'init', 'tm_custom_endpoints' );
      function tm_custom_endpoints() {
        add_rewrite_endpoint( 'warranties', EP_ROOT | EP_PAGES );
      } // end function
    
      // add new query vars.
      add_filter( 'query_vars', 'tm_custom_query_vars', 0 );
      function tm_custom_query_vars( $vars ) {
        $vars[] = 'warranties';
        return $vars;
      } // end function
    
      // insert the custom endpoints into the My Account menu
      add_filter( 'woocommerce_account_menu_items', 'tm_add_custom_endpoints' );
      function tm_add_custom_endpoints( $items ) {
        $items['warranties'] = 'Warranties';
        return $items;
      } // end function    
    
      add_action( 'woocommerce_account_warranties_endpoint', 'tm_warranties_content' );
      function tm_warranties_content() {
        print '.....';
      }
    Thread Starter s31concierge

    (@s31concierge)

    Saving Permalinks did it… that gets me everytime. BUT now the content is not loading. I suspect it’s because of this last function… I’m not sure how to interpret it for my page. My content is is https://dev.school31lofts.com/my-bookings. I can move that content if needed. This is the function I mean:

      add_action( 'woocommerce_account_warranties_endpoint', 'tm_warranties_content' );
      function tm_warranties_content() {
        print '.....';
      }

    Thanks for all your help on this.

    The action name must contain exactly whatever you have called your endpoint, so:
    add_action( ‘woocommerce_account_my-bookings_endpoint’, …

    The link is usually /my-account/something/ so for you it would be
    https://dev.school31lofts.com/my-account/my-bookings/

    You’ll need to change print ‘….’; to some code to generate in your content.

    Thread Starter s31concierge

    (@s31concierge)

    I feel like I may be drifting further from the hold grail. Here’s my code I removed the dash because the very last instance cause an error.

     register_activation_hook( __FILE__, 'tm_flush_rewrite_rules' );
      function tm_flush_rewrite_rules() {
        add_rewrite_endpoint( 'mybookings', EP_ROOT | EP_PAGES );
        flush_rewrite_rules();
      } // end function
    
      // register new endpoint to use for My Account page
      add_action( 'init', 'tm_custom_endpoints' );
      function tm_custom_endpoints() {
        add_rewrite_endpoint( 'mybookings', EP_ROOT | EP_PAGES );
      } // end function
    
      // add new query vars.
      add_filter( 'query_vars', 'tm_custom_query_vars', 0 );
      function tm_custom_query_vars( $vars ) {
        $vars[] = 'mybookings';
        return $vars;
      } // end function
    
      // insert the custom endpoints into the My Account menu
      add_filter( 'woocommerce_account_menu_items', 'tm_add_custom_endpoints' );
      function tm_add_custom_endpoints( $items ) {
        $items['mybookings'] = 'My Booking History';
        return $items;
      } // end function    
    
      add_action( 'woocommerce_account_mybookings_endpoint', 'tm_mybookings_content' );
      function tm_mybookings_content() {
        print '.....';
      }

    https://dev.school31lofts.com/my-account/mybookings/
    doesn’t exist, presumably you didn’t resave permalinks after changing the endpoint name.

    The endpoint can have a hyphen, many do. The function names can’t and have to have an underscrore instead.

    Thread Starter s31concierge

    (@s31concierge)

    That’s the other part.

    How in God’s name do you make a sub directory in WP?
    Or is it done in FTP?
    I just wonder if the theme element would work if I copied the page out of the root.

    If you add an endpoint to my-account, WP will put it at the end of the url. You have succeeded in doing this because:
    https://dev.school31lofts.com/my-account/my-bookings/
    resolves to page. Albeit if the user is not logged in he will see only the log in box. But if he were logged in, I’m sure he would see the page.

    Nothing to do with subdirectories, forget that.

    The files in the file system consist of a series of functions and templates – there isn’t a one-to-one correlation between files and pages. The content is in the database and is manipulated by the files.

    Thread Starter s31concierge

    (@s31concierge)

    Ok that clears up alot and I think I got it…short of knowing what string to put in the “print” snippet. I’ve tried the page name and URL string and those obviously are not it.

    Re you pulling in content from a page?

    $post_id = <post ID from page edit query string> ;
    $post = get_post( $post_id );
    print $post->post_content;
Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Adding custom content to My Account page’ is closed to new replies.