Override Dokan Includes File in Child Theme

I'm trying to override this Dokan plugin file in a child theme:

wp-content/plugins/dokan-pro/includes/modules/vendor-verification/templates/verification-new.php

I can successfully override files in the normal Dokan templates folder:

wp-content/plugins/dokan-pro/templates/path-to-file.php

by using

wp-content/themes/theme-child/dokan/path-to-file.php

However, because the file I wish to override is in the includes folder, I'm having trouble finding the correct file path to override the verification-new.php file.

Any ideas?

P.S. The reason why I wish to override the file in a child theme rather than simply edit the original is so I can update Dokan and not lose the changes.

Topic child-theme templates Wordpress

Category Web


To update Jo Kolov's answer, it almost works. But you have to change this line :

add_filter('dokan_locate_template', 'childtheme_dokan_locate_template', 20, 3);

To :

add_filter('dokan_get_template_part', 'childtheme_dokan_locate_template', 20, 3);

I was atttempting the same purpose.

Dokan support has confirmed that only files contained in the dokan templates/ directory can be overriden in your theme.

If you need to override modules's templates, I suggest to use this filter provided by dokan : 'dokan_locate_template'

You can use it in your child-theme functions.php like this :

add_filter('dokan_locate_template', 'childtheme_dokan_locate_template', 20, 3);
function childtheme_dokan_locate_template($template, $template_name, $template_path) {
    if ( preg_match('/\/modules\//i', $template) ) {
        $theme_template = str_replace(DOKAN_PRO_DIR . "/", get_stylesheet_directory() . '/' . dokan()->template_path(), $template);
        if ($template != $template_name && file_exists($theme_template)) {
            $template = $theme_template;
        }
    }
    return $template;
}

This code allows to override Dokan PRO modules templates in your child theme.

wp-content/plugins/dokan-pro/includes/modules/vendor-verification/templates/verification-new.php

is overriden by this one

wp-content/themes/your-child-theme/dokan/modules/vendor-verification/templates/verification-new.php

Hope it helps.


Child themes let you override templates, but these are not templates you're attempting to override. You can't drop in arbitrary files and override the parent theme, and WordPress can't do it's magic when include or require are used to load files.

The reason this works for templates, is because WordPress doesn't load them with include, instead it uses filterable functions with custom logic, such as get_template_part.

So there is no way to use the child theme method to swap out that file. You do have the advantage that the child themes functions.php loads first.

Instead, you're going to have to look at how the code in that theme loads itself, if it provides filters and actions, etc, much like you would when trying to override plugin code.

You'll need to contact the vendor for documentation and support, afterall you're a paying customer.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.