Skip to content

Commit a461142

Browse files
committed
force default WooCommerce templates
1 parent a74b505 commit a461142

File tree

4 files changed

+68
-32
lines changed

4 files changed

+68
-32
lines changed

assets/js/indexeddb.worker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/wcpos-functions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
use WCPOS\WooCommercePOS\Admin\Permalink;
20+
use WCPOS\WooCommercePOS\Logger;
2021
use const WCPOS\WooCommercePOS\PLUGIN_PATH;
2122
use WCPOS\WooCommercePOS\Services\Settings;
2223
use const WCPOS\WooCommercePOS\SHORT_NAME;
@@ -234,3 +235,38 @@ function woocommerce_pos_is_pos_order( $order ): bool {
234235
return 'woocommerce-pos' === $created_via || '1' === $legacy;
235236
}
236237
}
238+
239+
240+
if ( ! \function_exists( 'wcpos_get_woocommerce_template' ) ) {
241+
/**
242+
* Get a default WooCommerce template.
243+
*
244+
* @param string $template_name Template name.
245+
* @param array $args Arguments.
246+
*/
247+
function wcpos_get_woocommerce_template( $template_name, $args = array() ): void {
248+
$plugin_path = WC()->plugin_path();
249+
$template = trailingslashit( $plugin_path . '/templates' ) . $template_name;
250+
251+
/**
252+
* Filter the default WooCommerce template path.
253+
*
254+
* @param string $template Template path.
255+
* @param string $template_name Template name.
256+
* @param array $args Arguments.
257+
*/
258+
$template = apply_filters( 'wcpos_locate_woocommerce_template', $template, $template_name, $args );
259+
260+
if ( ! file_exists( $template ) ) {
261+
Logger::log( \sprintf( 'WooCommerce default template not found: %s', $template ) );
262+
263+
return;
264+
}
265+
266+
if ( $args && \is_array( $args ) ) {
267+
extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
268+
}
269+
270+
include $template;
271+
}
272+
}

templates/payment.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
wp_head();
1919
} else {
2020
// Manually call necessary functions when wp_head is disabled.
21-
if ( function_exists( 'wp_enqueue_block_template_skip_link' ) ) {
21+
if ( \function_exists( 'wp_enqueue_block_template_skip_link' ) ) {
2222
wp_enqueue_block_template_skip_link();
2323
}
2424
}
25-
?>
25+
?>
2626
<style>
2727
html, body, ul, li, fieldset, address {
2828
font-family: sans-serif;
@@ -310,38 +310,38 @@
310310
<body <?php body_class(); ?>>
311311
<div class="woocommerce">
312312
<?php
313-
// Troubleshooting form section
314-
echo $this->get_troubleshooting_form_html();
315-
?>
313+
// Troubleshooting form section
314+
echo $this->get_troubleshooting_form_html();
315+
?>
316316

317317
<?php woocommerce_output_all_notices(); ?>
318318

319319
<?php
320-
// Cashier details section
321-
echo $this->get_cashier_details_html();
322-
?>
320+
// Cashier details section
321+
echo $this->get_cashier_details_html();
322+
?>
323323

324324
<?php
325-
// Paying customer details section
326-
echo $this->get_paying_customer_details_html();
327-
?>
325+
// Paying customer details section
326+
echo $this->get_paying_customer_details_html();
327+
?>
328328

329329
<?php
330-
// Coupon form section
331-
echo $this->get_coupon_form_html();
332-
?>
330+
// Coupon form section
331+
echo $this->get_coupon_form_html();
332+
?>
333333

334334
<?php
335-
// WooCommerce payment form
336-
wc_get_template(
337-
'checkout/form-pay.php',
338-
array(
339-
'order' => $this->order,
340-
'available_gateways' => $available_gateways,
341-
'order_button_text' => $order_button_text,
342-
)
343-
);
344-
?>
335+
// WooCommerce payment form
336+
wcpos_get_woocommerce_template(
337+
'checkout/form-pay.php',
338+
array(
339+
'order' => $this->order,
340+
'available_gateways' => $available_gateways,
341+
'order_button_text' => $order_button_text,
342+
)
343+
);
344+
?>
345345
</div>
346346

347347
<?php

templates/received.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* HOWEVER, this is not recommended , don't be surprised if your POS breaks
77
*/
88

9-
defined( 'ABSPATH' ) || exit;
9+
\defined( 'ABSPATH' ) || exit;
1010
?>
1111
<!doctype html>
1212
<html <?php language_attributes(); ?>>
@@ -79,7 +79,7 @@
7979
}
8080
}
8181
</style>
82-
<?php if ( $order_complete ) : ?>
82+
<?php if ( $order_complete ) { ?>
8383
<script>
8484
(function() {
8585
// Parse the order JSON from PHP
@@ -102,22 +102,22 @@
102102
}
103103
})();
104104
</script>
105-
<?php endif; ?>
105+
<?php } ?>
106106
</head>
107107

108108
<body <?php body_class(); ?>>
109109
<div class="woocommerce">
110-
<?php if ( $order_complete ) : ?>
110+
<?php if ( $order_complete ) { ?>
111111
<div class="wrapper">
112112
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
113113
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
114114
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
115115
</svg>
116116
</div>
117-
<?php else : ?>
117+
<?php } else { ?>
118118
<?php woocommerce_output_all_notices(); ?>
119-
<?php wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) ); ?>
120-
<?php endif; ?>
119+
<?php wcpos_get_woocommerce_template( 'checkout/thankyou.php', array( 'order' => $order ) ); ?>
120+
<?php } ?>
121121
</div>
122122

123123
<?php wp_footer(); ?>

0 commit comments

Comments
 (0)