【问题标题】:Woocommerce add_to_cart giving me fatal errorWoocommerce add_to_cart 给我致命错误
【发布时间】:2015-05-20 17:35:50
【问题描述】:

我有以下代码使用 Woocommerce 插件将多个项目添加到购物车,它给了我致命错误:

致命错误:达到“100”的最大函数嵌套级别,正在中止!在 ...\wp-content\plugins\woocommerce\woocommerce.php 第 94 行

我也尝试增加嵌套级别,但没有帮助。 代码如下:

add_action( 'init', 'multi_add_to_cart' );
function multi_add_to_cart() {
    if( !isset( $_POST['multi_add_to_cart_nonce'] )  ) return false;
    if ( !wp_verify_nonce( $_POST['multi_add_to_cart_nonce'], 'multi_add_to_cart_nonce') ) return false;
    global $woocommerce;
    $added_products = 0;
    foreach( $_POST['multi_add_to_cart'] as $variation_id => $variation ) {
        if( (int) $variation['quantity'] > 0 ) {
            $woocommerce->cart->add_to_cart(
                $variation['product_id'],   // string $product_id
                $variation['quantity'],     // string $quantity = 1
                (int) $variation_id,        // integer $variation_id = ''
                ( isset($variation['attributes']) && !empty($variation['attributes']) ) ? $variation['attributes'] : false // Attributes!
            );
           $added_products++;
        }
    }
    if( $added_products > 0 ) woocommerce_add_to_cart_message($variation['product_id'] );
}

【问题讨论】:

  • 这很奇怪......我看不出代码有任何问题......也许是你的服务器......试试看stackoverflow.com/questions/8656089/…
  • 谢谢,但我已经阅读了上面的文章,但没有任何帮助:(我的 centos 服务器和本地主机都显示此错误。
  • 尝试将init 更改为template_redirect...只是猜测..
  • @Reigel:非常感谢。这解决了我的问题:D 非常感谢它

标签: php wordpress woocommerce


【解决方案1】:

可能有很多函数与init 挂钩。尝试将init 更改为template_redirect

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多