1

I am making a plugin that adds some functionality to woocommerce. I dislike the bland default woocommerce "my account dashboard" page and I would like to change the way the dashboard looks. I have been looking online and it seems the only way to do this would be to modify the theme or the template inside of woocommerce plugin itself.

I want to make my plugin as portable as possible therefore, I would like for my plugin to modify the my account dashboard page, and not the PHP code of the template or the woocommerce plugin. Is there a way to do this as a plugin?

1 Answer 1

0

I ended up doing it in what I would consider a sloppy way. On the init hook I check the WooCommerce template against my custom template and if the WooCommerce template does not match my template then I replace the WooCommerce template with my template.

add_action( 'init', 'run_inital' );
function run_inital(){
    $wooThemePath = $woocommerce->plugin_path()."/templates/myaccount/dashboard.php";
    $myThemeFile = file_get_contents(plugin_dir_path( __FILE__ )."/WooCommerce/dashboard.php");
    $WooThemeFile = file_get_contents($wooThemePath);
    if($myThemeFile != $WooThemeFile){
        $Woo_Theme = fopen($wooThemePath, "w");
        fwrite($Woo_Theme, $myThemeFile);
    }

}

If you wanted to make this snippet better you should check to see if the file sizes are different instead of comparing the contents.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.