我正在使用在这里获得帮助的功能对Woocommerce结帐进行重新排序:Change checkout order review section in Wooocommerce
问题是,如果装运国不是瑞典,我还需要禁用付款方式“ COD”,所以我也有以下代码:
function payment_gateway_disable_by_country( $available_gateways ) {
// Abort if in admin area
if ( is_admin() ) {
return $available_gateways;
}
$billing_country = WC()->customer->get_country();
$shipping_country = ! empty( WC()->customer->get_shipping_country() ) ? WC()->customer->get_shipping_country() : $billing_country;
if ( isset( $available_gateways['cod'] ) && $shipping_country != 'SE' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_by_country' );
,但是这两个代码不能一起使用。如果我仅使用第二个代码(付款方式部分)而不使用reordeing,则它可以正常工作,并且付款方式会根据选择的运输国家/地区自动更新。但是,如果我还添加了重新排序代码,则仅在刷新页面时付款方式不会自动更改。我该如何调整重新排序的代码,以便两者一起工作?