对于WooCommerce促销折扣:买10送1感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍10送一怎样算折扣,并为您提供关于php–Woocommerce3中购物车商品数量累进百分比折扣、p
对于WooCommerce促销折扣:买10送1感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍10送一怎样算折扣,并为您提供关于php – Woocommerce 3中购物车商品数量累进百分比折扣、php – Woocommerce:找不到woocommerce / templates /目录、php – Woocommerce:替换弃用的挂钩“woocommerce_add_order_item_meta”、php – 以编程方式为Woocommerce 3添加有条件的折扣的有用信息。
本文目录一览:- WooCommerce促销折扣:买10送1(10送一怎样算折扣)
- php – Woocommerce 3中购物车商品数量累进百分比折扣
- php – Woocommerce:找不到woocommerce / templates /目录
- php – Woocommerce:替换弃用的挂钩“woocommerce_add_order_item_meta”
- php – 以编程方式为Woocommerce 3添加有条件的折扣
WooCommerce促销折扣:买10送1(10送一怎样算折扣)
要使其适用于多种产品,您可以使用 init() {
// Title text color
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.backgroundColor = .clear
// Clear list background color
UITableView.appearance().separatorStyle = .none
UITableViewCell.appearance().backgroundColor = .clear
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().selectionStyle = .none
}
var body: some View {
NavigationView {
ZStack {
LinearGradient(gradient: Gradient(colors: [Color("DarkShade"),Color("PrimaryDark")]),startPoint: .top,endPoint: .bottom)
.edgesIgnoringSafeArea(.all)
List(self.viewModel.rooms.enumerated().map({ $0 }),id: \.element.id) { (index,room) in
ZStack {
RoomsItemView(room: room)
.onAppear(perform: {
let count = self.viewModel.rooms.count
if index == count - 1 {
self.viewModel.loadRooms(currentListSize: count)
}
})
NavigationLink(destination: GuestRoomView(room: room)) {
EmptyView()
}
}
}
}
.pullToRefresh(isShowing: self.$isRefreshing,onRefresh: self.onRefresh)
.navigationBarTitle("rooms_title")
.navigationBarBackButtonHidden(true)
.navigationBarItems(
leading:
Button(action: {
self.shouldShowSpotifyAuth = false
}) {
VStack {
Spacer()
HStack {
Image(systemName: "chevron.left")
.resizable()
.scaledToFit()
.frame(height: 20.0)
Spacer()
}
Spacer()
}
.frame(width: 40.0,height: 30.0)
},trailing:
Button(action: {
print("create room")
}) {
VStack {
Spacer()
HStack {
Spacer()
Image(systemName: "plus")
.resizable()
.scaledToFit()
.frame(height: 20.0)
}
Spacer()
}
.frame(width: 40.0,height: 30.0)
}
)
}
.onAppear(perform: {
self.onRefresh()
})
.onReceive(viewModel.onRoomsUpdate) {
self.isRefreshing = false
}
.gesture(DragGesture().updating($dragOffset,body: { (value,state,transaction) in
if(value.startLocation.x < 20 && value.translation.width > 100) {
self.shouldShowSpotifyAuth = false
}
})
)
}
php函数,如下所示:
in_array()
代码进入您的活动子主题(或活动主题)的function.php文件中,已经过测试并且可以正常工作。
php – Woocommerce 3中购物车商品数量累进百分比折扣
我正在尝试对购物车中的所有商品应用TOTAL CART折扣,具体取决于添加的商品数量.我已经从answer here中获取并修改了代码示例,并使大部分逻辑工作.
但是我不能让它适用于下面描述的两种情况.它还仅将规则应用于购物车中的单个项目.不是整个购物车.
场景:
>如果购物车中没有商品在9-12之间,则对所有商品应用5%折扣.
>如果购物车中没有商品在13-16之间,则对所有商品应用10%折扣.
>折扣不应该叠加.例如购物车中有12件商品,可享5%折扣……添加13件商品,可享受5%优惠并享受10%优惠.
码:
add_filter('woocommerce_add_cart_item_data', 'add_items_default_price_as_custom_data', 20, 3 );
function add_items_default_price_as_custom_data( $cart_item_data, $product_id, $variation_id ){
$product_id = $variation_id > 0 ? $variation_id : $product_id;
## ----- YOUR SETTING ----- ##
$discount_percentage = 5; // discount (5%)
// The WC_Product Object
$product = wc_get_product($product_id);
// Only for non on sale products
if( ! $product->is_on_sale() ){
$price = (float) $product->get_price();
// Set the Product default base price as custom cart item data
$cart_item_data['base_price'] = $price;
// Set the Product discounted price as custom cart item data
$cart_item_data['new_price'] = $price * (100 - $discount_percentage) / 100;
// Set the percentage as custom cart item data
$cart_item_data['percentage'] = $discount_percentage;
}
return $cart_item_data;
}
// display the product original price
add_filter('woocommerce_cart_item_price', 'display_cart_items_default_price', 20, 3 );
function display_cart_items_default_price( $product_price, $cart_item, $cart_item_key ){
if( isset($cart_item['base_price']) ) {
$product = $cart_item['data'];
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $cart_item['base_price'] ) ) );
}
return $product_price;
}
// display the product name with the discount percentage
add_filter( 'woocommerce_cart_item_name', 'append_percetage_to_item_name', 20, 3 );
function append_percetage_to_item_name( $product_name, $cart_item, $cart_item_key ){
if( isset($cart_item['percentage']) && isset($cart_item['base_price']) ) {
if( $cart_item['data']->get_price() != $cart_item['base_price'] )
$product_name .= ' <em>(' . $cart_item['percentage'] . '% discounted)</em>';
}
return $product_name;
}
add_action( 'woocommerce_before_calculate_totals', 'custom_discounted_cart_item_price', 20, 1 );
function custom_discounted_cart_item_price( $cart ) {
## ----- YOUR SETTING ----- ##
$balanced_qty = 9; // Targeted quantity
$upper_balanced_qty = 12; // Max quantity limit
// Loop through cart items
foreach ( $cart->get_cart() as $cart_item ) {
// For item quantity between 9 and 12
if( ($cart_item['quantity'] >= $balanced_qty && isset($cart_item['new_price']) && ($cart_item['quantity'] <= $upper_balanced_qty) ) ){
// Set cart item discounted price
$cart_item['data']->set_price($cart_item['new_price']);
}
}
}
解决方法:
您可以按购物车商品数量或全球购物车商品数量来执行此操作:
1)按购物车数量:
// Utility function that give the discount percentage based on quantity argument
function get_discount_percent( $quantity ){
if( $quantity < 9 )
$percent = 0; // 0 % ( quantity from 1 to 8 )
elseif( $quantity >= 9 && $quantity < 13 )
$percent = 5; // 5 % ( quantity from 9 to 12 )
else
$percent = 10; // 10 % ( quantity up to 13 )
return $percent;
}
add_filter('woocommerce_add_cart_item_data', 'add_items_default_price_as_custom_data', 20, 3 );
function add_items_default_price_as_custom_data( $cart_item_data, $product_id, $variation_id ){
$product_id = $variation_id > 0 ? $variation_id : $product_id;
## ----- YOUR SETTING ----- ##
$percent_1 = 5; // discount (5%)
$percent_2 = 10; // discount (10%)
// The WC_Product Object
$product = wc_get_product($product_id);
$price = (float) $product->get_price();
// Set the Product default base price as custom cart item data
$cart_item_data['discount'][0] = $price;
// Set the Product discounted price of 5% as custom cart item data
$cart_item_data['discount'][$percent_1] = $price * (100 - $percent_1) / 100;
// Set the Product discounted price of 10% as custom cart item data
$cart_item_data['discount'][$percent_2] = $price * (100 - $percent_2) / 100;
return $cart_item_data;
}
// display the product original price
add_filter('woocommerce_cart_item_price', 'display_cart_items_default_price', 20, 3 );
function display_cart_items_default_price( $product_price, $cart_item, $cart_item_key ){
if( isset($cart_item['discount'][0]) ) {
$product = $cart_item['data'];
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $cart_item['discount'][0] ) ) );
}
return $product_price;
}
// display the product name with the discount percentage
add_filter( 'woocommerce_cart_item_name', 'append_percetage_to_item_name', 20, 3 );
function append_percetage_to_item_name( $product_name, $cart_item, $cart_item_key ){
// get the percent based on quantity
$percent = get_discount_percent($cart_item['quantity']);
if( isset($cart_item['discount'][$percent]) && isset($cart_item['discount'][0]) ) {
if( $cart_item['data']->get_price() != $cart_item['discount'][0] )
$product_name .= ' <em>(' . $percent . '% discounted)</em>';
}
return $product_name;
}
add_action( 'woocommerce_before_calculate_totals', 'set_custom_discount_cart_item_price', 25, 1 );
function set_custom_discount_cart_item_price( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
foreach( $cart->get_cart() as $cart_item ){
// get the percent based on quantity
$percentage = get_discount_percent($cart_item['quantity']);
// For items non on sale set a discount based on quantity as defined in
if( $percentage != 0 && isset($cart_item['discount'][$percentage]) && ! $cart_item['data']->is_on_sale() ) {
$cart_item['data']->set_price($cart_item['discount'][$percentage]);
}
}
}
代码位于活动子主题(或活动主题)的function.PHP文件中.经过测试和工作.
2)全球购物车项目数(非销售产品):
// Utility function that give the discount percentage based on quantity argument
function get_discount_percent( $quantity ){
if( $quantity < 9 )
$percent = 0; // 0 % ( quantity from 1 to 8 )
elseif( $quantity >= 9 && $quantity < 13 )
$percent = 5; // 5 % ( quantity from 9 to 12 )
else
$percent = 10; // 10 % ( quantity up to 13 )
return $percent;
}
// Utility function that count cart items that are not on sale
function get_non_on_sale_cart_items_count(){
$items_count = 0;
foreach( WC()->cart->get_cart() as $cart_item ){
if( ! $cart_item['data']->is_on_sale() ){
$items_count += $cart_item['quantity'];
}
}
return $items_count;
}
add_filter('woocommerce_add_cart_item_data', 'add_items_default_price_as_custom_data', 20, 3 );
function add_items_default_price_as_custom_data( $cart_item_data, $product_id, $variation_id ){
$product_id = $variation_id > 0 ? $variation_id : $product_id;
## ----- YOUR SETTING ----- ##
$percent_1 = 5; // discount (5%)
$percent_2 = 10; // discount (10%)
// The WC_Product Object
$product = wc_get_product($product_id);
$price = (float) $product->get_price();
// Set the Product default base price as custom cart item data
$cart_item_data['discount'][0] = $price;
// Set the Product discounted price of 5% as custom cart item data
$cart_item_data['discount'][$percent_1] = $price * (100 - $percent_1) / 100;
// Set the Product discounted price of 10% as custom cart item data
$cart_item_data['discount'][$percent_2] = $price * (100 - $percent_2) / 100;
return $cart_item_data;
}
// display the product original price
add_filter('woocommerce_cart_item_price', 'display_cart_items_default_price', 20, 3 );
function display_cart_items_default_price( $product_price, $cart_item, $cart_item_key ){
if( isset($cart_item['discount'][0]) ) {
$product = $cart_item['data'];
$product_price = wc_price( wc_get_price_to_display( $product, array( 'price' => $cart_item['discount'][0] ) ) );
}
return $product_price;
}
// display the product name with the discount percentage
add_filter( 'woocommerce_cart_item_name', 'append_percetage_to_item_name', 20, 3 );
function append_percetage_to_item_name( $product_name, $cart_item, $cart_item_key ){
// Get cart items count
$items_count = get_non_on_sale_cart_items_count();
// get the percent based on quantity
$percent = get_discount_percent($items_count);
if( isset($cart_item['discount'][$percent]) && isset($cart_item['discount'][0]) ) {
if( $cart_item['data']->get_price() != $cart_item['discount'][0] )
$product_name .= ' <em>(' . $percent . '% discounted)</em>';
elseif ( $cart_item['data']->is_on_sale() && $percent != 0 ){
$product_name .= ' <em>(Item on sale)</em>';
}
}
return $product_name;
}
// Change cart item price
add_action( 'woocommerce_before_calculate_totals', 'set_custom_discount_cart_item_price', 25, 1 );
function set_custom_discount_cart_item_price( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
// Get cart items count
$items_count = get_non_on_sale_cart_items_count();
// get the percent based on quantity
$percentage = get_discount_percent($items_count);
foreach( $cart->get_cart() as $cart_item ){
// For items non on sale set a discount based on quantity as defined in
if( $percentage != 0 && isset($cart_item['discount'][$percentage]) && ! $cart_item['data']->is_on_sale() ) {
$cart_item['data']->set_price($cart_item['discount'][$percentage]);
}
}
}
代码位于活动子主题(或活动主题)的function.PHP文件中.经过测试和工作.
Here below, in this example, the third item is on sale, so the real count is
10 + 1 = 11
items and then the discount for11
items is5%
:07001
php – Woocommerce:找不到woocommerce / templates /目录
我正在尝试使用WooCommerce为我的网站建立一个商店.我的目标是删除产品档案/商店基页上的“产品类别”(可能还有“搜索”框).我知道编辑“product-archive.PHP”文件是必需的.但我只是找不到它!它应该在woocommerce / templates /目录中的某个地方,但是没有这样的目录!
我正在使用Fruitfulcode的Fruitful主题.我正在使用最新版本的wordpress和WooCommerce.我几乎尝试了任何东西:安装和重新安装WooCommerce,安装旧版本的WooCommerce ……没有任何作用.我的主题中没有任何woocommerce / templates目录!
你能帮助我吗?难道我做错了什么?
解决方法:
我觉得你对WooCommerce template overrides的运作方式有点困惑.以下是您应该注意的一些重要信息:
>安装WooCommerce根本不会修改你的主题.
>您的主题中不应该有woocommerce / templates /目录,即使主题覆盖默认的WooCommerce模板也是如此.相反,你可能有一个woocommerce /目录(没有templates /目录).
>通过将模板文件从/wp-content/plugins/woocommerce/templates/xxx.PHP复制到wp-content / themes / yourtheme / woocommerce / xxx.PHP来覆盖WooCommerce模板
如果您没有在主题中看到woocommerce目录,则表示您的主题使用默认的WooCommerce模板.如果要覆盖它们,则需要将product-archive.PHP模板从WooCommerce插件模板目录复制到主题中的woocommerce /目录中.
更多信息in the WooCommerce documentation.
php – Woocommerce:替换弃用的挂钩“woocommerce_add_order_item_meta”
需要为订单商品添加自定义元.谷歌搜索它,大多数文章说使用“woocommerce_add_order_item_Meta”钩子.此挂钩在最新版本2.3.7中已弃用.有人,请告诉我使用哪个钩子.
http://docs.woothemes.com/wc-apidocs/function-woocommerce_add_order_item_meta.html
解决方法:
如果你看一下wc-deprecated-functions.PHP,你会看到
/**
* @deprecated
*/
function woocommerce_add_order_item_Meta( $item_id, $Meta_key, $Meta_value, $unique = false ) {
return wc_add_order_item_Meta( $item_id, $Meta_key, $Meta_value, $unique );
}
基本上,该函数已重命名为wc_add_order_item_Meta(),因此如果您需要该函数,则使用该函数.动作挂钩未重命名,并保留在class-wc-checkout.PHP中:
// Allow plugins to add order item Meta
do_action( 'woocommerce_add_order_item_Meta', $item_id, $values, $cart_item_key );
php – 以编程方式为Woocommerce 3添加有条件的折扣
我只找到了附加优惠券或以编程方式创建优惠券的解决方案.我在结账时没有发现临时优惠券.
同样重要的是,这张优惠券可以与其他优惠券相结合,而不是更多.
这是我的代码:
if ( get_discount_points() < 100 ) { //Customer has bonus status 1 } elseif ( get_discount_points() < 200 ) { //Customer has bonus status 2 } else { //Customer has bonus status x
按折扣百分比计算
}
这甚至可能吗?
解决方法
function get_customer_discount(){ if( $points = get_discount_points() ){ if ( $points < 100 ) { return 1; // 1 % discount } elseif ( $points < 200 ) { return 2; // 2.5 % discount } else { return 4; // 5 % discount } } else { return false; } } add_action( 'woocommerce_cart_calculate_fees','custom_discount',10,1 ); function custom_discount( $cart ){ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Only for 2 items or more if( $percentage = get_customer_discount() ){ $discount = WC()->cart->get_subtotal() * $percentage / 100; // Apply discount to 2nd item for non on sale items in cart if( $discount > 0 ) $cart->add_fee( sprintf( __("discount %s%%"),$percentage),-$discount ); } }
代码位于活动子主题(或活动主题)的function.PHP文件中.经过测试和工作.
关于WooCommerce促销折扣:买10送1和10送一怎样算折扣的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于php – Woocommerce 3中购物车商品数量累进百分比折扣、php – Woocommerce:找不到woocommerce / templates /目录、php – Woocommerce:替换弃用的挂钩“woocommerce_add_order_item_meta”、php – 以编程方式为Woocommerce 3添加有条件的折扣等相关知识的信息别忘了在本站进行查找喔。
本文标签: