Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WooCommerce为预订购启用的产品提供有条件付款逃避_Woocommerce - Fatal编程技术网

WooCommerce为预订购启用的产品提供有条件付款逃避

WooCommerce为预订购启用的产品提供有条件付款逃避,woocommerce,Woocommerce,我试图显示Moneris支付逃逸只对产品的预订购启用 我看我们可以在产品类型上做。现在我想知道如何检测产品是否已启用预订购 我试过这样的方法,但没用: add_filter('woocommerce_available_payment_gateways', 'conditional_payment_gateways', 10, 1); function conditional_payment_gateways( $available_gateways ) { // Not in back

我试图显示Moneris支付逃逸只对产品的预订购启用

我看我们可以在产品类型上做。现在我想知道如何检测产品是否已启用预订购

我试过这样的方法,但没用:

add_filter('woocommerce_available_payment_gateways', 'conditional_payment_gateways', 10, 1);
function conditional_payment_gateways( $available_gateways ) {
    // Not in backend (admin)
    if( is_admin() ) 
        return $available_gateways;

    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $prod_pre = false;
        // Get the WC_Product object
        $product = wc_get_product($cart_item['product_id']);
        // Get the product types in cart (example)
     
        if ($product->class_exists( 'WC_Pre_Orders_Order' )) $prod_pre = true;

    }

      // Remove moneris payment gateway for preordered products
    if($prod_pre)
        unset($available_gateways['moneris']); // unset 'moneris'


    return $available_gateways;
}

要检测您的产品是否已启用预订购,它应该具有一个通常与元数据相关的属性,这比您执行此操作的方式要好。请尝试在
wp_postemta
数据库表中查找应具有预订购选项的给定产品id。