如何解决WC->购物车-> remove_cart_item$ cart_item_key之后如何在购物车上显示消息-Woocommerce
我正在尝试与我的ERP一起检查是否有库存产品。因此,当您选择添加到购物车时,我将运行代码检查是否有库存,然后将其删除(如果无库存)。我想显示一条消息,说该产品已删除,导致缺货。
function custom_validate_stock() {
if(1==1){
$stockERP = 0;
if($stockERP < 1){
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product->id ){
WC()->cart->remove_cart_item($cart_item_key);
$removed = true;
break;
}
}
}
}
if($removed){
remove_action( 'woocommerce_cart_is_empty','wc_empty_cart_message',10 );
add_action( 'woocommerce_cart_is_empty','custom_empty_cart_message',10 );
}
}
}
function custom_empty_cart_message() {
$html = '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">';
$html .= wp_kses_post( apply_filters( 'wc_empty_cart_message',__( 'Your product is out of stock,please refresh the page.','woocommerce' ) ) );
echo $html . '</p></div>';
}
解决方法
紧接着
import 'package:flutter/material.dart';
import 'package:flutter_tindercard/flutter_tindercard.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',theme: ThemeData(
primarySwatch: Colors.blue,),home: ExampleHomePage(),);
}
}
class ExampleHomePage extends StatefulWidget {
@override
_ExampleHomePageState createState() => _ExampleHomePageState();
}
class _ExampleHomePageState extends State<ExampleHomePage>
with TickerProviderStateMixin {
List<String> welcomeImages = [
"https://picsum.photos/250?image=9","https://picsum.photos/250?image=10","https://picsum.photos/250?image=11","https://picsum.photos/250?image=12","https://picsum.photos/250?image=13","https://picsum.photos/250?image=14"
];
int currentIndex = 0;
@override
Widget build(BuildContext context) {
CardController controller; //Use this to trigger swap.
return new Scaffold(
body: new Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.6,child: new TinderSwapCard(
swipeUp: true,swipeDown: true,orientation: AmassOrientation.BOTTOM,totalNum: welcomeImages.length,stackNum: 3,swipeEdge: 4.0,maxWidth: MediaQuery.of(context).size.width * 0.9,maxHeight: MediaQuery.of(context).size.width * 0.9,minWidth: MediaQuery.of(context).size.width * 0.8,minHeight: MediaQuery.of(context).size.width * 0.8,cardBuilder: (context,index) => Card(
child: Image.network('${welcomeImages[index]}'),cardController: controller = CardController(),swipeUpdateCallback: (DragUpdateDetails details,Alignment align) {
/// Get swiping card's alignment
if (align.x < 0) {
//Card is LEFT swiping
print("left");
} else if (align.x > 0) {
print("right");
//Card is RIGHT swiping
}
},swipeCompleteCallback:
(CardSwipeOrientation orientation,int index) {
currentIndex = index;
print("$currentIndex ${orientation.toString()}");
/// Get orientation & index of swiped card!
},);
}
}
我想您可以添加一个通知:
WC()->cart->remove_cart_item($cart_item_key);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。