Skip to content

Commit

Permalink
add error message for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Nov 24, 2023
1 parent edbac8d commit f6ced73
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions includes/wcpos-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,37 +134,49 @@ function woocommerce_pos_json_encode( $data ) {
}

/*
* Return template path
* Return template path for a given template
*
* @param string $path
* @param string $template
*
* @return mixed|void
* @return string|null
*/
if ( ! \function_exists( 'woocommerce_pos_locate_template' ) ) {
function woocommerce_pos_locate_template( $path = '' ) {
$template = locate_template(array(
'woocommerce-pos/' . $path,
));

if ( ! $template ) {
$template = PLUGIN_PATH . 'templates/' . $path;
function woocommerce_pos_locate_template( $template = '' ) {
// check theme directory first
$path = locate_template(
array(
'woocommerce-pos/' . $template,
)
);

// if not, use plugin template
if ( ! $path ) {
$path = PLUGIN_PATH . 'templates/' . $template;
}

if ( file_exists( $template ) ) {
/*
* Filters the template path.
*
* @param {array} $template
* @param {string} $path
*
* @returns {array} $template
*
* @since 1.0.0
*
* @hook woocommerce_pos_locate_template
*/
return apply_filters( 'woocommerce_pos_locate_template', $template, $path );
/*
* Filters the template path.
*
* @param {string} $template
* @param {string} $path
*
* @returns {string} $path
*
* @since 1.0.0
*
* @hook woocommerce_pos_locate_template
*/
$filtered_path = apply_filters( 'woocommerce_pos_locate_template', $path, $template );

// Check if the filtered template file exists
if ( file_exists( $filtered_path ) ) {
return $filtered_path;
}

// Echo a message or handle the error as needed if the file path does not exist
echo "The template file '" . esc_html($filtered_path) . "' does not exist.";

return null;
}
}

Expand Down

0 comments on commit f6ced73

Please sign in to comment.