Home Forums Theme Support Dokan Product Edit page issue and rewrites

This topic is: resolved

This topic contains 4 replies, has 3 voices, and was last updated by  Mahi 5 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19415

    Simon
    Member
    Post count: 58

    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.

    #19417

    Marita
    Member
    Post count: 7

    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

    #19419

    Simon
    Member
    Post count: 58

    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.

    #19421

    Simon
    Member
    Post count: 58

    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. ๐Ÿ™

    #19429

    Mahi
    Member
    Post count: 1555

    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 5 posts - 1 through 5 (of 5 total)

The topic ‘Product Edit page issue and rewrites’ is closed to new replies.