Product Edit page issue and rewrites

This topic contains 4 reply and 3 voices, and was last updated by Mahi 9 years, 11 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
April 25, 2014 at 10:48 pm 19415
Mahi I've created a child theme and have been editing some of the product pages to remove fields that are not necessary for my site. I've come across a weird bug in the process. In the products.php file you're calling the product-edit page if the action = edit. This seems fine if the product hasn't been published, but once the product has been published then the edit link URL on product listing page changes from something like "...?product_id=247&action=edit" to ".../product-name/edit". This is causing an issue where the system is using my customized product-edit template until the product has been published, then if a user goes back to the "dashboard - products" page and clicks on edit, then it starts using parent template instead.
April 25, 2014 at 10:55 pm 19417
Marita Marita

I had similar issues with the EDIT product page not working – and it was the permalink structure in my settings – i had to set it to /product

April 25, 2014 at 11:14 pm 19419
Simon Simon

Thanks Marita… I think this is a little different situation.

Here’s the code in the product.php file

<?php
/**
 * Template Name: Dashboard - Products
 */

dokan_redirect_login();
dokan_redirect_if_not_seller();

$action = isset( $_GET['action'] ) ? $_GET['action'] : 'listing';

if ( $action == 'edit' ) {

    include get_stylesheet_directory() . '/product-edit.php';

} else {
    include get_stylesheet_directory() . '/products-listing.php';
}

So this is looking for a GET with the parameter ‘action’ and that parameter must equal ‘edit’.

Since the URL is being rewritten to pretty permalinks once the product is published there is no longer a URL that looks like this “/dashboard/products/?product_id=246&action=edit” instead it looks like this “/product-name/edit”.

So I think an additional statement is needed in the if to account for the change in URL structure.

April 26, 2014 at 12:31 am 19421
Simon Simon

I figured out the cause. In the rewrites.php file is this function:

    function product_edit_template( $template ) {
        if ( get_query_var( 'edit' ) && is_singular( 'product' ) ) {

            return get_template_directory() . '/templates/product-edit.php';
        }

        return $template;
    }

Since it’s using get_template_directory it’s not seeing the same file in the child theme. I tried adding the same directory/file to my child theme and then changing get_template_directory() to get_stylesheet_directory(), but it’s not recognizing it.

Probably has something to do with the function being part of a class that is being called in the functions.php file in the parent theme.

I can change get_template_directory() to get_stylesheet_directory() in the parent theme’s rewrites.php file, but any updates will overwrite it. 🙁

April 26, 2014 at 4:13 am 19429
Mahi Mahi

unfortunately, it will overwrite when next update comes out.

Good news is team is working hard on it to make sure next version is compatible for child themes. So sorry for any inconvenience.

Viewing 4 Posts - 1 through 4 (of 4 total)