From 0fe9535df166e8a1865f86e27942a54c40e97dbc Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Sun, 14 Jan 2024 19:03:33 +0100 Subject: [PATCH] add amount tendered and change to checkout and receipt --- includes/Gateways/Cash.php | 60 ++++++++++++++++++++++++++++++-------- readme.txt | 5 ++++ templates/receipt.php | 18 ++++++++++++ 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/includes/Gateways/Cash.php b/includes/Gateways/Cash.php index b77454a..3709c1e 100644 --- a/includes/Gateways/Cash.php +++ b/includes/Gateways/Cash.php @@ -1,5 +1,4 @@ query_vars['order-pay'] ) ? $wp->query_vars['order-pay'] : null; + $order = $order_id ? wc_get_order( $order_id ) : null; + if ( $this->description ) { echo '

' . wp_kses_post( $this->description ) . '

'; } @@ -70,16 +77,45 @@ public function payment_fields(): void { } echo ' -
- -
- ' . $left_addon . ' - - ' . $right_addon . ' -
- ' . wp_nonce_field( 'pos_cash_payment_nonce', 'pos_cash_payment_nonce_field' ) . ' -
+
+
+ +
+ ' . $left_addon . ' + + ' . $right_addon . ' +
+
+
+ +
+
+ ' . wp_nonce_field( 'pos_cash_payment_nonce', 'pos_cash_payment_nonce_field' ) . ' +
'; + + if ( $order && $order->get_total() > 0 ) { + echo ' + + '; + } } /** @@ -102,8 +138,8 @@ public function process_payment( $order_id ): array { $tendered = wc_format_decimal( wp_unslash( $_POST['pos-cash-tendered'] ) ); } $change = $tendered > $order->get_total() ? wc_format_decimal( floatval( $tendered ) - floatval( $order->get_total() ) ) : '0'; - update_post_meta( $order_id, '_pos_cash_amount_tendered', $tendered ); - update_post_meta( $order_id, '_pos_cash_change', $change ); + $order->update_meta_data( '_pos_cash_amount_tendered', $tendered ); + $order->update_meta_data( '_pos_cash_change', $change ); if ( $tendered >= $order->get_total() ) { // payment complete diff --git a/readme.txt b/readme.txt index 0f75d50..9307193 100644 --- a/readme.txt +++ b/readme.txt @@ -63,6 +63,11 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co == Changelog == += 1.4.5 - 2024/01/14 = +* Add: show change in checkout modal and receipt for the Cash gateway +* Add: use 'medium' sized product image instead of 'thumbnail' +* Fix: compatibility with alternative login urls, eg: WPS Hide Login + = 1.4.4 - 2024/01/12 = * Desktop App: fix login for Desktop Application v1.4.0 diff --git a/templates/receipt.php b/templates/receipt.php index 541a32c..874b889 100644 --- a/templates/receipt.php +++ b/templates/receipt.php @@ -263,6 +263,24 @@ get_total() ) ); ?> + get_payment_method() === 'pos_cash' ) : ?> + get_meta( '_pos_cash_amount_tendered' ); + $change_given = $order->get_meta( '_pos_cash_change' ); + ?> + + + + + + + + + + + + +