Skip to content

Commit

Permalink
Fix: add enabled POS gateways to the Order Edit select input
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Mar 5, 2024
1 parent e3e35f1 commit a080b70
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
35 changes: 35 additions & 0 deletions includes/Admin/Orders/Single_Order.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
<?php
/**
* Single Order
*
* @package WCPOS\WooCommercePOS
*/

namespace WCPOS\WooCommercePOS\Admin\Orders;

use WC_Abstract_Order;

/**
*
*/
class Single_Order {

/**
*
*/
public function __construct() {
add_filter( 'wc_order_is_editable', array( $this, 'wc_order_is_editable' ), 10, 2 );
add_action( 'woocommerce_admin_order_data_after_order_details', array( $this, 'add_cashier_select' ) );
add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_cashier_select' ) );

$this->add_available_gateways();
}

/**
* We need to add the POS gateways to the available gateways for the edit order dropdown.
* It's possible another plugin could just re-init after us, but this will work for most cases.
*/
public function add_available_gateways() {
if ( WC()->payment_gateways() ) {
$payment_gateways = WC()->payment_gateways->payment_gateways;
$settings = woocommerce_pos_get_settings( 'payment_gateways' );

// Add POS gateways to the available gateways for the edit order dropdown.
foreach ( $payment_gateways as $gateway ) {
if ( isset( $settings['gateways'][ $gateway->id ] ) && $settings['gateways'][ $gateway->id ]['enabled'] ) {
$gateway->enabled = 'yes';
}
}

// Directly set the modified gateways back to the WooCommerce Payment Gateways instance
WC()->payment_gateways->payment_gateways = $payment_gateways;
}
}

/**
Expand Down
10 changes: 5 additions & 5 deletions includes/Gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ public function payment_gateways( array $gateways ) {
*
* - NOTE: lots of plugins/themes call this filter and I can't guarantee that $gateways is an array
*
* @param null|array $gateways
* @param null|array $gateways The available payment gateways.
*
* @return null|array
* @return null|array The available payment gateways.
*/
public function available_payment_gateways( ?array $gateways ): ?array {
// early exit
// early exit.
if ( ! woocommerce_pos_request() ) {
return $gateways;
}

// use POS settings
// use POS settings.
$settings = woocommerce_pos_get_settings( 'payment_gateways' );

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

$_available_gateways = array();
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co

== Changelog ==

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

= 1.4.10 - 2024/01/23 =
Expand Down

0 comments on commit a080b70

Please sign in to comment.