未捕获的错误:调用未定义函数 wc() 和 WC()

问题描述 投票:0回答:0

我刚刚在当前活动的子主题中创建了一个名为

custom_functions.php
的文件,当我尝试使用这行简单的代码将产品添加到购物车时,出现错误:

代码:

<?php
    WC()->cart->add_to_cart( 204 );
    //wc()->cart->add_to_cart( 204 );
?>

错误:

 Fatal error: Uncaught Error: Call to undefined function WC() in /homepages/11/d870651981/htdocs/clickandbuilds/XXXXXXX/wp-content/themes/motors-child/custom_functions.php:2 Stack trace: #0 {main} thrown in /homepages/11/d870651981/htdocs/clickandbuilds/XXXXXXX/wp-content/themes/motors-child/custom_functions.php on line 2

我一直在网上看到你不需要导入任何其他东西,只需使用

WC()
.

我正在使用

functions.php
jQuery AJAX
文件执行该代码。

我做错了什么?

php wordpress woocommerce
© www.soinside.com 2019 - 2024. All rights reserved.