WooCommerce从购物车中删除特定产品的优惠券字段

时间:2020-06-15 14:11:35

标签: php woocommerce

我在第228行附近的子主题的functions.php文件中出现致命错误。这是本节。该代码的目的是在客户订购礼品券时在购物车页面上隐藏优惠券字段。

add_filter( 'woocommerce_coupons_enabled','ts_hide_coupon_field_on_cart' );
function ts_hide_coupon_field_on_cart( $enabled ) {
$product_id = 2400;
$cart = WC()->cart->get_cart();
foreach ( $cart as $id => $cart_item ) {
    if( $cart_item[ 'data' ]->get_id() == $product_id ) {
        return false;
    }
}   

return $enabled;
}

有人可以帮助我修复错误吗?一切正常,但是今天早上我们遇到了一个订单问题(完全无关),但我不知何故应该归咎于此错误。 TIA。

7-14-20:一个更新,该错误仍然是我的问题。当更新到最新的WooCommerce版本时,该网站引发了致命错误。我现在已经从functions.php文件中删除了代码。我将继续对其进行故障排除;任何帮助将不胜感激。

根据建议,这是错误:

[Tue Jul 14 14:37:27.117532 2020] [php7:error] [pid 18971] [client 2603:301b:2601:b100:1948:a111:c595:46d7:42976] PHP致命错误:未捕获的错误:在/nas/content/live/ketoliciousllc/wp-content/themes/ketolicious/functions.php:228\nStack trace:\ n#0 / nas / content / live / ketoliciousllc /中,调用成员函数get_cart()上的null wp-includes / class-wp-hook.php(287):ts_hide_coupon_field_on_cart(true)\ n#1 /nas/content/live/ketoliciousllc/wp-includes/plugin.php(206):WP_Hook-> apply_filters(true,数组)\ n#2 /nas/content/live/ketoliciousllc/wp-content/plugins/woocommerce/includes/wc-coupon-functions.php(69):apply_filters('woocommerce_cou ...',true)\ n# 3 /nas/content/live/ketoliciousllc/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Assets.php(157):wc_coupons_enabled()\ n#4 / nas / content / live / ketoliciousllc / wp -includes / class-wp-hook.php(287):Automattic \ WooCommerce \ Blocks \ Assets :: get_wc_block_data(Array)\ n#5 /nas/content/live/ketoliciousllc/wp-includes/plugin.php(206) :WP_Hook-> apply_filters(Array,Array)\ n#6 /nas/content/live/ketoliciousllc/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Assets/AssetDataRegistry.php(136):/ nas / content中的应用/live/ketoliciousllc/wp-content/themes/ketolicious/functions.php,第228行,引荐网址:https://ketoliciousllc.com/wp-admin/themes.php

0 个答案:

没有答案