【发布时间】:2015-03-17 13:45:15
【问题描述】:
我在 Woocommerce (wordpress) 中创建了一个网上商店。这是一家葡萄酒商店,我需要增加额外费用:每瓶 0.08 欧元(产品)。
我已经找到并对其进行了调整,但我无法将产品(瓶子)的数量乘以 0.08 欧元。 在购物车中,我确实得到了一条额外的线,但值为 0。
谁能解释我做错了什么?
function get_cart_contents_count() {
return apply_filters( 'woocommerce_cart_contents_count', $this->cart_contents_count );
}
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Custom', 'woocommerce'), $get_cart_contents_count * 0.08 );
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
【问题讨论】:
-
$get_cart_contents_count是一个未定义的变量,PHP 会礼貌地将其视为0。也许您想要get_cart_contents_count()(即:函数调用)。 -
谢谢马克,但是当我尝试这个时,页面没有加载。
标签: php wordpress woocommerce