Php 基于商业订单支付中的特定产品标签限制支付网关

Php 基于商业订单支付中的特定产品标签限制支付网关,php,wordpress,woocommerce,payment-gateway,taxonomy-terms,Php,Wordpress,Woocommerce,Payment Gateway,Taxonomy Terms,我想在Woocommerce Bookings支付页面上根据产品标签显示支付网关,并位于URL扩展名上,如: /checkout/order pay/5759158/?为订单付款=正确&关键=wc订单\u 75uA3d1z1fmCT 例如,如果标签的id为“378”,则仅显示“PayPal”网关,并删除其他网关 我使用的是应答码,它允许根据产品标签限制支付网关,但仅限于Woocommerce结帐页面 我需要限制在Woocommerce预订付款页面上 如何基于Woocommerce Booking

我想在Woocommerce Bookings支付页面上根据产品标签显示支付网关,并位于URL扩展名上,如:
/checkout/order pay/5759158/?为订单付款=正确&关键=wc订单\u 75uA3d1z1fmCT

例如,如果标签的id为“378”,则仅显示“PayPal”网关,并删除其他网关

我使用的是应答码,它允许根据产品标签限制支付网关,但仅限于Woocommerce结帐页面

我需要限制在Woocommerce预订付款页面上


如何基于Woocommerce Bookings支付页面中的产品标签限制支付网关?

对于订单支付页面,您需要循环浏览订单项目而不是购物车项目,以检查产品标签条款…以目标订单支付页面使用:

if ( is_wc_endpoint_url( 'order-pay' ) ) {
当订单付款页面(以及结帐)中有属于特定产品标签条款的项目时,以下代码将禁用除“paypal”之外的所有付款方式:

代码进入活动子主题(或活动主题)的functions.php文件。它应该会起作用

见:


相关:

谢谢你Loic-我已经尝试添加if
(is_checkout()| | is_wc_endpoint_url('order pay')){
但它仍然显示woocommerce订单支付页面上的所有网关。@MarkoI.更新了…现在应该可以工作了。谢谢你Loic!非常感谢。
add_filter( 'woocommerce_available_payment_gateways', 'filter_available_payment_gateways' );
function filter_available_payment_gateways( $available_gateways ) {
    // Here below your settings
    $taxonomy    = 'product_tag'; // Targeting WooCommerce product tag terms (or "product_cat" for category terms)
    $terms       = array('378'); // Here define the terms (can be term names, slugs or ids)
    $payment_ids = array('paypal'); // Here define the allowed payment methods ids to keep
    $found       = false; // Initializing

    // 1. For Checkout page
    if ( is_checkout() && ! is_wc_endpoint_url() ) {
        // Loop through cart items
        foreach ( WC()->cart->get_cart() as $item ) {
            if ( ! has_term( $terms, $taxonomy, $item['product_id'] ) ) {
                $found = true;
                break;
            }
        }
    }
    // 2. For Order pay
    elseif ( is_wc_endpoint_url( 'order-pay' ) ) {
        global $wp;

        // Get WC_Order Object from the order id
        $order = wc_get_order( absint($wp->query_vars['order-pay']) );

        // Loop through order items
        foreach ( $order->get_items() as $item ) {
            if ( ! has_term( $terms, $taxonomy, $item->get_product_id() ) ) {
                $found = true;
                break;
            }
        }
    }

    if ( $found ) {
        foreach ( $available_gateways as $payment_id => $available_gateway ) {
            if ( ! in_array($payment_id, $payment_ids) ) {
                unset($available_gateways[$payment_id]);
            }
        }
    }
    return $available_gateways;
}