我开始从事小型 Woocommerce 项目。我有 3 个进入这家商店的支付网关:Paypal、信用卡和直接银行转账。
我想要的是:如果使用优惠券代码,我想从可用的支付网关中禁用(或删除)Paypal 和信用卡,并保留“直接银行转账”作为可用的支付网关选择。
从结帐页面显示当前状态的外观:
我找到了一个类似的解决方案,但这是用于根据产品类别删除网关。
add_filter( 'woocommerce_available_payment_gateways', 'unset_payment_gateways_by_category' );
function unset_payment_gateways_by_category( $available_gateways ) {
global $woocommerce;
$unset = false;
$category_ids = array( 8, 37 );
foreach ( $woocommerce->cart->cart_contents as $key => $values ) {
$terms = get_the_terms( $values['product_id'], 'product_cat' );
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $category_ids ) ) {
$unset = true;
break;
}
}
}
if ( $unset == true )
unset( $available_gateways['cheque'] );
return $available_gateways;
}
Run Code Online (Sandbox Code Playgroud)
所以我认为可以使用此功能,但根据我的问题稍作修改。
任何帮助表示赞赏。