如何仅为“支票”网关禁用“下订单”按钮。我不希望我的用户为此网关下订单,因为他们需要在进行任何付款之前通过给定的信息进行联系。
我找到了针对特定运输类别的删除 Woocommerce“下订单”按钮,这是我想要做的,而是用于“支票”付款方式。
我试图用“支票”ID 替换 ID 332,但它完全删除了所有网关的按钮。它在后端的 ID 是cheque
和结帐页面上的 ID 和类payment_method_cheque
。
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
function remove_order_button_html( $button ) {
// HERE define your targeted shipping class
$targeted_payment_method = 'payment_method_cheque';
$found = false;
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ) {
if( $cart_item['data']->get_shipping_class_id() == $targeted_shipping_class ) {
$found = true; // The targeted shipping class is found
break; // We stop the loop
}
}
// If found we remove the button
if( $found )
$button = '';
return $button;
}
但它不起作用。有什么建议吗?