Last active
June 3, 2023 01:01
-
-
Save everaldomatias/39e382a01603ca1c06cf6e0c6e7f8f47 to your computer and use it in GitHub Desktop.
Enqueue WooCommerce template from plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_locate_template', 'custom_woocommerce_locate_template', 10, 3 ); | |
function custom_woocommerce_locate_template( $template, $template_name, $template_path ) { | |
global $woocommerce; | |
$_template = $template; | |
if ( ! $template_path ) $template_path = $woocommerce->template_url; | |
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/'; | |
$template = locate_template( | |
[ | |
$template_path . $template_name, | |
$template_name | |
] | |
); | |
if( ! $template && file_exists( $plugin_path . $template_name ) ) | |
$template = $plugin_path . $template_name; | |
if ( ! $template ) | |
$template = $_template; | |
return $template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment