In my child theme’s functions.php I have this function
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_cash_on_delivery' );
function payment_gateway_cash_on_delivery( $available_gateways ) {
$selected_shipping_id = WC()->session->get( 'chosen_shipping_methods' )[0];
if ( in_array($selected_shipping_id, ['flexible_shipping_5_5', 'flexible_shipping_7_6' ]) && isset( $available_gateways['bacs'] )) {
unset( $available_gateways['bacs'] );
}
return $available_gateways;
}
WP sends me these warnig about an error at the first row of the function
Podrobnosti chyby
=================
Na řádku č. 61 v souboru /hosting/www/weftsandwarps.com/Zlaterouno/wp-content/themes/storefront-child/functions.php došlo k chybě typu E_ERROR. Chybová zpráva: Uncaught Error: Call to a member function get() on null in /hosting/www/weftsandwarps.com/Zlaterouno/wp-content/themes/storefront-child/functions.php:61
Stack trace:
#0 /hosting/www/weftsandwarps.com/Zlaterouno/wp-includes/class-wp-hook.php(307): payment_gateway_cash_on_delivery()
#1 /hosting/www/weftsandwarps.com/Zlaterouno/wp-includes/plugin.php(189): WP_Hook->apply_filters()
#2 /hosting/www/weftsandwarps.com/Zlaterouno/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php(160): apply_filters()
#3 /hosting/www/weftsandwarps.com/Zlaterouno/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/OnboardingTasks.php(91): WC_Payment_Gateways->get_available_payment_gateways()
#4 /hosting/www/weftsandwarps.com/Zlaterouno/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/OnboardingTasks.php(148): AutomatticWooCommerceAdminFeaturesOnboardingTasks::get_settings()
#5 /hosting/www/weftsandwarps.com/Zlaterouno/wp-includes/class-wp-hook.php(307): AutomatticWooComm
My guess is the function is called when no method has been chosen?