Skip to content

Commit a080b70

Browse files
committed
Fix: add enabled POS gateways to the Order Edit select input
1 parent e3e35f1 commit a080b70

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

includes/Admin/Orders/Single_Order.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
<?php
2+
/**
3+
* Single Order
4+
*
5+
* @package WCPOS\WooCommercePOS
6+
*/
27

38
namespace WCPOS\WooCommercePOS\Admin\Orders;
49

510
use WC_Abstract_Order;
611

12+
/**
13+
*
14+
*/
715
class Single_Order {
16+
17+
/**
18+
*
19+
*/
820
public function __construct() {
921
add_filter( 'wc_order_is_editable', array( $this, 'wc_order_is_editable' ), 10, 2 );
1022
add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'add_cashier_select' ) );
1123
add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_cashier_select' ) );
24+
25+
$this->add_available_gateways();
26+
}
27+
28+
/**
29+
* We need to add the POS gateways to the available gateways for the edit order dropdown.
30+
* It's possible another plugin could just re-init after us, but this will work for most cases.
31+
*/
32+
public function add_available_gateways() {
33+
if ( WC()->payment_gateways() ) {
34+
$payment_gateways = WC()->payment_gateways->payment_gateways;
35+
$settings = woocommerce_pos_get_settings( 'payment_gateways' );
36+
37+
// Add POS gateways to the available gateways for the edit order dropdown.
38+
foreach ( $payment_gateways as $gateway ) {
39+
if ( isset( $settings['gateways'][ $gateway->id ] ) && $settings['gateways'][ $gateway->id ]['enabled'] ) {
40+
$gateway->enabled = 'yes';
41+
}
42+
}
43+
44+
// Directly set the modified gateways back to the WooCommerce Payment Gateways instance
45+
WC()->payment_gateways->payment_gateways = $payment_gateways;
46+
}
1247
}
1348

1449
/**

includes/Gateways.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ public function payment_gateways( array $gateways ) {
5656
*
5757
* - NOTE: lots of plugins/themes call this filter and I can't guarantee that $gateways is an array
5858
*
59-
* @param null|array $gateways
59+
* @param null|array $gateways The available payment gateways.
6060
*
61-
* @return null|array
61+
* @return null|array The available payment gateways.
6262
*/
6363
public function available_payment_gateways( ?array $gateways ): ?array {
64-
// early exit
64+
// early exit.
6565
if ( ! woocommerce_pos_request() ) {
6666
return $gateways;
6767
}
6868

69-
// use POS settings
69+
// use POS settings.
7070
$settings = woocommerce_pos_get_settings( 'payment_gateways' );
7171

72-
// Get all payment gateways
72+
// Get all payment gateways.
7373
$all_gateways = WC()->payment_gateways->payment_gateways;
7474

7575
$_available_gateways = array();

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co
6363

6464
== Changelog ==
6565

66-
= 1.4.11 - 2024/02/27 =
66+
= 1.4.11 - 2024/03/XX =
6767
* Fix: regression in tax calculation when POS settings are different to Online settings
6868
* Fix: regression in product variation images, use 'medium' sized product image instead of full size
6969
* Fix: remove POS Only products from frontend WC REST API response
7070
* Fix: generic get meta method should not be used for '_create_via'
71+
* Fix: add enabled POS gateways to the Order Edit select input
7172
* Fix: other minor PHP warnings
7273

7374
= 1.4.10 - 2024/01/23 =

0 commit comments

Comments
 (0)