在WooCommerce中,如何根据购物车中的商品总数设置购物车折扣?
例如:
我搜索互联网但没有找到任何解决方案或插件可用.
谢谢.
我一直在寻找一段时间,但我找不到如何以程序方式删除woocommerce优惠券.
我正在尝试根据购物车总数制作折扣.我需要申请删除优惠券,因为如果你有价值1000欧元的产品(15%优惠券适用)并且删除产品并且只留下价值50欧元的产品,你仍然可以享受15%的折扣,因为我的代码没有删除已经申请的优惠券.
所以这是我现在的代码:
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$coupon_code5 = '5p'; // your coupon code here
$coupon_code10 = '10p'; // your coupon code here
$coupon_code15 = '15p'; // your coupon code here
$coupon_code20 = '20p'; // your coupon code here
$coupon_code25 = '25p'; // your coupon code here
if ( $woocommerce->cart->has_discount( $coupon_code ) ){
return;
}
if ( $woocommerce->cart->cart_contents_total >= 4000 ) {
$woocommerce->cart->add_discount( $coupon_code25 );
$woocommerce->show_messages();
}
else if ( $woocommerce->cart->cart_contents_total >= 2000 ) { …
Run Code Online (Sandbox Code Playgroud) 在WooCommerce中,我想特别针对那些没有销售的产品给予10%的折扣.如果购物车商品数量为5件或更多商品而非销售,那么我给予10%的折扣.
我使用以下代码根据购物车项目计数限制获得折扣:
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
/**
* Add custom fee if more than three article
* @param WC_Cart $cart
*/
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count < 5 ){
return;
}
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.1;
$cart->add_fee( '10% discount', -$discount);
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何仅对未售出的商品应用折扣.我怎样才能实现它?
谢谢.
如果没有使用优惠券功能,我想对特定付款方式 ID(例如“xyz”)应用 15% 的折扣。
我需要帮助确定要使用哪些钩子。我想要实现的总体想法是:
if payment_method_hook == 'xyz'{
cart_subtotal = cart_subtotal - 15%
}
Run Code Online (Sandbox Code Playgroud)
客户不需要在此页面上看到折扣。我希望正确提交折扣,仅适用于特定的付款方式。
我需要手动设置折扣而不使用优惠券。
我已经检查了 Github 中的 Woocommerce 源,我看到它使用了“set_discount_total”函数,但它不起作用。
我试过了WC()->cart->set_discount_total(15)
,$order->set_discount_total(15);
但没有。
这是我的代码:
<?php
function letsgo_order_total($order_id, $posted_data, $order) {
$order = wc_get_order( $order_id );
$order->set_discount_total(50);
}
add_action('woocommerce_checkout_order_processed','letsgo_order_total',10,3);
?>
Run Code Online (Sandbox Code Playgroud)
实际上我发现了一种方法,它可以工作,但我不喜欢代码:
<?php
$cart_discount = 50;
$discount = (double)get_post_meta($order_id,'_cart_discount',true);
update_post_meta($order_id,'_cart_discount',$cart_discount + $discount);
?>
Run Code Online (Sandbox Code Playgroud) 我有一个使用 WooCommerce 插件的 WordPress 网站。如果买家选择本地取货作为运输方式,我想为他们提供购物车总额 5% 的折扣。
我已经尝试过- 5 * [qty]但它似乎不起作用。
我也试过 -0.95 * [cost] 没有运气
在我的 WooCommerce 网站中,我有一些价格相同的产品80 美元。
\n我想按产品数量添加折扣。
逻辑是这样的:
\n\nif (Products Quantity is 2){\n // the original product price change from 80$ to 75$ each.\n}\n\nif(Products Quantity is 3 or more){\n //the original product price change from 80$ to 70$ each. \n}\n
Run Code Online (Sandbox Code Playgroud)\n\n例如,
\n\n\n\n\n如果顾客选择了 2 个产品,则原价为
\n(80$ x 2)
=>160$
。\n
折扣后价格为:(75$ x 2)
=>150$
。
和\xe2\x80\xa6
\n\n\n如果访客选择了 3 个产品,则原价将为
(80$ x 3)
=>240$
。\n
但扣除费用后,将为:(70$ x 3) …
如何获取和修改购物车中第二件商品的价格?
我想对第二个产品进行-3%的折扣(购物车中的商品已按价格排序,最高的顶部)。
我认为它必须计算在woocommerce_before_calculate_totals
或喜欢折扣woocommerce_cart_calculate_fees
?
谢谢
在Woocommerce,我想根据客户的总购买金额设置百分比折扣.例如,如果总购买金额大于或等于200$
,则客户获得5%
折扣.
所以,我有第一部分代码来显示总和:
function get_customer_total_order() {
$customer_orders = get_posts( array(
'numberposts' => - 1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed' )
) );
$total = 0;
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$total += $order->get_total();
}
return $total;
}
Run Code Online (Sandbox Code Playgroud)
我想将我的代码与此答案的代码一起使用:
基于WooCommerce中购物车总数的累进折扣
有没有办法使用它们来设置基于所有订单总和的折扣?
我使用正常的 woocommerce 优惠券方法创建了一张“ BOGOF ”(买一送一)优惠券。
该优惠券为用户提供购物车中其他 1 件商品 100% 的折扣。
优惠券设置
一般的:
折扣类型:百分比折扣 优惠券
数量:100
使用限制:
- 限制使用 X 项:1
使用时:
期望:
通过以下代码,我尝试实现我的目标,不幸的是没有达到预期的结果
function filter_woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $instance ) {
$price_array = array();
foreach( $cart_item as $item ) {
echo $item->price;
if($item->price > 0){
array_push($price_array, $item->price);
}
}
$lowestPrice = min($price_array);
if( $lowestPrice < $discount ){
$discount = $lowestPrice;
}
return $discount;
}
add_filter( 'woocommerce_coupon_get_discount_amount', 'filter_woocommerce_coupon_get_discount_amount', 10, 5 …
Run Code Online (Sandbox Code Playgroud)