0

I want to customize a plugin which uses a file called html-vendor-order-page.php to define the style of contents:

include_once( apply_filters( 'wcpv_vendor_order_page_template', dirname( __FILE__ ) . '/views/html-vendor-order-page.php' ) );

I want to create my own html-vendor-order-page.php by modifying this file and force the plugin to use this file instead by using add_filter.

I was thinking to filter __FILE__ which is a defined constant to point to my file.

Is that possible?

1 Answer 1

1

You can't just filter __FILE__. Or any arbitrary function or variable. You can only filter values that are passed to apply_filters(). In this case the wcpv_vendor_order_page_template filterable value is:

dirname( __FILE__ ) . '/views/html-vendor-order-page.php'

In other words, it's a path to a PHP file. If you want to change the PHP file that's loaded, you can filter wcpv_vendor_order_page_template to pass the path to a file in your theme.

So if you create a version of this file in wp-content/{yourtheme}/wcpv//views/html-vendor-order-page.php, you can make the plugin load that version like this:

add_filter(
    'wcpv_vendor_order_page_template',
    function( $path ) {
        return get_theme_file_path( 'wcpv//views/html-vendor-order-page.php' );
    }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.