Hello,
i get the following error message: Warning: Undefined property: WooCommerce::$payment_gateways in ...
/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway/src/Checkout/DisableGateways.php on line 118
I tried the known workaround but couldn't find the code snippet to change: https://wpml.org/errata/woocommerce-payment-details-are-displayed-twice-on-the-order-confirmation-page-e-mail/
Code:
<?php
use WCML\Multicurrency\Transient\Hooks as TransientHooks;
/**
* Class WCML_Currencies_Payment_Gateways
*/
class WCML_Currencies_Payment_Gateways {
const OPTION_KEY = 'wcml_custom_payment_gateways_for_currencies';
/** @var WCML_Payment_Gateway[] */
private $payment_gateways;
/** @var array */
private $available_gateways;
/** @var array */
private $supported_gateways;
/** @var woocommerce_wpml */
private $woocommerce_wpml;
/** @var WPML_WP_API */
private $wp_api;
/**
* @param woocommerce_wpml $woocommerce_wpml
* @param WPML_WP_API $wp_api
*/
public function __construct( woocommerce_wpml $woocommerce_wpml, WPML_WP_API $wp_api ) {
$this->woocommerce_wpml = $woocommerce_wpml;
$this->wp_api = $wp_api;
}
public function add_hooks() {
/**
* Since WC 8.5 we have `wc_payment_gateways_initialized` to load our code only when
* needed. Before that, we have to use `wp_loaded` and get the instance ourselves,
* which causes gateways to be loaded on every request.
*/
$hook = version_compare( WC_VERSION, '8.5', '>=' )
? 'wc_payment_gateways_initialized'
: 'wp_loaded';
add_action( $hook, [ $this, 'init_gateways' ] );
add_filter( 'woocommerce_gateway_description', [ $this, 'filter_gateway_description' ], 10, 2 );
add_filter( 'option_woocommerce_stripe_settings', [ 'WCML_Payment_Gateway_Stripe', 'filter_stripe_settings' ] );
add_filter( 'option_woocommerce-ppcp-settings', [ 'WCML_Payment_Gateway_PayPal_V2', 'filter_ppcp_args' ] );
TransientHooks::addHooks( WCML_Payment_Gateway_PayPal_V2::BEARER_TOKEN_TRANSIENT );
if ( ! is_admin() && wcml_is_multi_currency_on() ) {
add_filter(
'woocommerce_paypal_supported_currencies',
[ 'WCML_Payment_Gateway_PayPal', 'filter_supported_currencies' ]
);
}
}
/**
* @param string $currency
*
* @return bool
*/
public function is_enabled( $currency ) {
$gateway_enabled_settings = $this->get_settings();
if ( isset( $gateway_enabled_settings[ $currency ] ) ) {
return $gateway_enabled_settings[ $currency ];
}
return false;
}
/**
* @param string $currency
* @param bool $value
*/
public function set_enabled( $currency, $value ) {
$gateway_enabled_settings = $this->get_settings();
$gateway_enabled_settings[ $currency ] = $value;
update_option( self::OPTION_KEY, $gateway_enabled_settings );
}
/**
* @return array
*/
private function get_settings() {
return get_option( self::OPTION_KEY, [] );
}
/**
* @param WC_Payment_Gateways|null $wc_payment_gateways
*/
public function init_gateways( $wc_payment_gateways = null ) {
if ( null !== $this->payment_gateways ) {
return;
}
if ( ! $wc_payment_gateways ) {
$wc_payment_gateways = WC()->payment_gateways();
}
$this->payment_gateways = [];
$this->available_gateways = [];
$this->supported_gateways = [];
do_action( 'wcml_before_init_currency_payment_gateways' );
$this->available_gateways = $wc_payment_gateways->get_available_payment_gateways();
$this->supported_gateways = [
'bacs' => 'WCML_Payment_Gateway_Bacs',
'paypal' => 'WCML_Payment_Gateway_PayPal',
'ppcp-gateway' => 'WCML_Payment_Gateway_PayPal_V2',
'stripe' => 'WCML_Payment_Gateway_Stripe',
];
$this->supported_gateways = apply_filters( 'wcml_supported_currency_payment_gateways', $this->supported_gateways );
$this->store_supported_gateways();
$this->store_non_supported_gateways();
}
/**
* @return array
*/
public function get_gateways() {
$this->init_gateways();
return $this->payment_gateways;
}
/**
* @return array
*/
public function get_supported_gateways() {
$this->init_gateways();
|