• Hey everyone,

    I am developing a plugin for Jigoshop and I need help with a (possibly) simple problem that I can’t seem to fix.

    I want to create a link in the account page that opens in a way just like the “my orders” page. So far, I’ve only managed to create an endpoint and query vars and check if the query vars include the query var I added. Then I add my template to the page using the template_include hook. This adds my template to the main account page. I want to be able to replicate the “my orders” page but then with my own settings.

    To summarize:

    What I get now is my template below the footer on the account page.
    What I want is my template to open as a new page, in a same way as the My Orders page.

    Anyone got an idea on how to do that? I’m not so experienced with wordpress so it might be easier than I thought.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello,
    You will have to create a class which implements the PageInterface interface. Something along the lines of the below:

    <?php
    
    use Jigoshop\Helper\Render as RenderCore;
    use Jigoshop\Frontend\Page\PageInterface;
    use Jigoshop\Integration\Helper\Render;
    
    class MySettings implements PageInterface
    {
        function __construct()
        {
            Render::addLocation('my_settings_Plugin', my_settings_DIR);
            add_action('init', function () {
                add_rewrite_endpoint("my_settings", EP_ROOT | EP_PAGES | EP_PERMALINK);
                add_filter('generate_rewrite_rules', function ($rewrite) {
                    $mySettings = [
                        '^account/my_settings/?$' => 'index.php?pagename=my_settings'
                    ];
                    $rewrite->rules = $mySettings + $rewrite->rules;
                    return $rewrite->rules;
                });
                flush_rewrite_rules();
            });
            add_filter('jigoshop.frontend.page_resolver.page', function ($args) {
                global $wp_query;
                if ($wp_query->query['pagename'] == 'my_settings') {
                    return $this;
                }
                return $args;
            });
        }
    
        public function action()
        {
            $this->renderMySettings();
        }
    
        public function render()
        {
        }
    
        public function renderMySettings()
        {
            RenderCore::output('layout/ defautlt', [
                'content' => Render::get('my_settings_Plugin', 'my_settings_template', $args)
            ]);
            exit;
        }
    }

    Replace “my_settings” with your preferred plugin name. “my_settings_Plugin” will be your plugin’s name, “my_settings_DIR” is your plugin’s directory. “my_settings_template” is the name of the rendered template without the “.php” suffix.

    Thread Starter nielss

    (@nielss)

    @azrielnefezen you are truly amazing. Thank you very much for this. It works! Your answer has given me some insight on how this works and will definitely help me in the future as well. Thanks a lot!

    Thread Starter nielss

    (@nielss)

    @azrielnefezen I have some questions that I came up with during the application of this solution:

    – How to I correctly set the title of the page when I arrive on my settings page? I get “page not found” as the title.
    – I found out that to mimic the styling of for example the My Orders page, I have to use the css class wrap to wrap the primary and aside elements. How would I do this? I was only able to wrap content in primary.

    Thanks in advance.

    EDIT: I had more questions but I solved one.

    • This reply was modified 6 years, 1 month ago by nielss.
    • This reply was modified 6 years, 1 month ago by nielss.
    • This reply was modified 6 years, 1 month ago by nielss.
    Thread Starter nielss

    (@nielss)

    In short:

    Atm the page looks like this: https://imgur.com/a/WdrZepo

    While I want it to look like this: https://imgur.com/a/sgIhOhi

    Plugin Author Jigo Ltd

    (@jigoshop)

    Basically, copy the below file into your template and adjust it according to your needs:
    https://github.com/jigoshop/Jigoshop-eCommerce/blob/master/templates/user/account/orders.php

    Thread Starter nielss

    (@nielss)

    I tried doing this, but the same things seems to be happening. I copied the exact orders.php page but I still get this difference in styling. I noticed a few things when I copy the orders.php page:

    – The styling is off, which is likely because there is no div with the wrap class around the elements with primary and secondary.
    – There is no page title. It is set to “page not found” but I still end up at my page.

    Do you know if anything could’ve gone wrong?

    • This reply was modified 6 years, 1 month ago by nielss.
    • This reply was modified 6 years, 1 month ago by nielss.
    Thread Starter nielss

    (@nielss)

    Anyone got an idea how to make sure I do get this right?

    I feel like it has to do something with the chosen layout type? Are there more? I can’t find any documentation on these kind of things.

    My only problem at the moment is:

    When I make a page as shown above, it works perfectly apart from:

    – The page doesn’t wrap the primary and secondary content with a div that has the ‘wrap’ class. This makes the styling weird while I guess it should be possible?
    – The page has the title “page not found”

    Please help me!

    Thread Starter nielss

    (@nielss)

    I solved a part of the problem! I found out that there are different layouts for some themes and I appear to use twentyseventeen, which is different from the rest. I solved that problem.

    My only problem now is: I get a 404 error when I go to my page. It still works fine, but the page title is “page not found” and some of the css even has 404 classes.

    Any ideas?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Development: Custom account panel. Similar to “my orders” behaviour’ is closed to new replies.