我需要开发一个插件,适用于购物车折扣,如果x数量的产品已经购买。有人能告诉我需要使用的代码/API的方向吗。
无法从中找到任何内容https://docs.woothemes.com/documentation/plugins/woocommerce/woocommerce-codex/ 而且,不要仅仅为了获得这样一些简单的功能而花100多美元购买官方批量折扣插件。
我发现了WooCommerce\'s get_total_discount() function 应用woocommerce_cart_total_discount
过滤器,但我似乎无法成功地进入该过滤器。。。
function mwe_calculate_discount( $total_discount, $cart ) {
//global $woocommerce;
$num_products_required_for_discount = 4;
echo "<!-- Discount? -->";
$number_products = $cart->cart_contents_count;
if ($number_products >= $num_products_required_for_discount) {
echo "<!-- QUALIFIES FOR DISCOUNT! -->";
for ($i = 0; $i < $number_products; $i++) {
// Get the reduced price of the product - TODO
// Calculate $product_discount
$product_discount = 11.11; // TODO
// Add $product_discount to the $total_discount
$total_discount += $product_discount;
}
echo "<!-- Total discount: $total_discount -->";
}
else {
echo "<!-- NO DISCOUNT -->";
}
return $total_discount;
}
add_filter(\'woocommerce_cart_total_discount\', \'mwe_calculate_discount\', 10, 2);
。。。知道我的代码有什么问题吗?