WooCommerce - 如何检查特定产品是否在购物车中。任何钩子?

时间:2015-11-05 18:09:57

标签: wordpress woocommerce

是否有任何钩子,检查是否有任何特定产品被添加到购物车?

1 个答案:

答案 0 :(得分:3)

您可以使用WC_Cart $cart_id方法在购物车中找到商品。您需要使用find_product_in_cart()生成$product_id = 123456; // Some product id $product_cart_id = WC()->cart->generate_cart_id( $product_id ); // Returns an empty string, if the cart item is not found $in_cart = WC()->cart->find_product_in_cart( $product_cart_id ); if ( $in_cart ) { // Do something if the product is in the cart } else { // Do something if the product is not in the cart } ,以便执行此操作:

String url = "http://www.yell4food.com/json/json_vocher.php?discount=" + code;