我在通过代码添加优惠券折扣时遇到问题。我收到此错误
致命错误:第 43 行 C:\xampp\htdocs\teachingyounet\wp-content\themes\responsive\functions.php 中的非对象调用成员函数 add_discount()
我的代码:
function zkr_add_discount(){
global $woocommerce;
global $total_weight;
if (current_user_can('distributor') || current_user_can('administrator')) {
//do stuff for administrator roles
wp_get_current_user();
//$coupon = $current_user->cimy_uef_COUPON;
$coupon = get_the_author_meta( 'cimy_uef_COUPON', $current_user->ID );
//$wc = new WC_Cart;
//print_r($wc->coupons_enabled());die;
//if($wc->coupons_enabled())
/*$code = $coupon;
$the_coupon = new WC_Coupon( $code );*/
//$wc->add_discount('testcoupon'); //sanitize_text_field( $coupon )
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon ))){
$woocommerce->show_messages();
}
}
}
我以为我有答案,但我错了:(
提前致谢。