如果购物车是免费的,我想在Woocommerce结帐中隐藏结算明细,所以我试图在主题functions.php中获得购物车价格,我收到此错误:
Call to a member function get_cart_total() on a non-object
我尝试使用的代码是:
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
global $woocommerce;
if ( $woocommerce->cart->get_cart_total() == 0 ) {
function kia_filter_billing_fields($fields){
unset( $fields["billing_email"] );
unset( $fields["billing_last_name"] );
unset( $fields["billing_first_name"] );
unset( $fields["billing_country"] );
unset( $fields["billing_company"] );
unset( $fields["billing_address_1"] );
unset( $fields["billing_address_2"] );
unset( $fields["billing_city"] );
unset( $fields["billing_state"] );
unset( $fields["billing_postcode"] );
unset( $fields["billing_phone"] );
return $fields;
}
}
我在互联网的帮助下度过了这里,但我被困住了。如果你能帮助我,我将不胜感激。
答案 0 :(得分:1)
您需要将代码包装在函数中,以便仅在执行woocommerce_checkout_process
操作时调用它。
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
function wc_minimum_order_amount()
{
global $woocommerce;
if ( $woocommerce->cart->get_cart_total() == 0 ) {
function kia_filter_billing_fields($fields){
unset( $fields["billing_email"] );
unset( $fields["billing_last_name"] );
unset( $fields["billing_first_name"] );
unset( $fields["billing_country"] );
unset( $fields["billing_company"] );
unset( $fields["billing_address_1"] );
unset( $fields["billing_address_2"] );
unset( $fields["billing_city"] );
unset( $fields["billing_state"] );
unset( $fields["billing_postcode"] );
unset( $fields["billing_phone"] );
return $fields;
}
}
}