cart

Check for Product Category in cart items with WooCommerce

喜你入骨 提交于 2019-12-11 04:18:01
问题 I'm trying to make a condition, where a function displays on WooCommerce checkout page only, if any product from category ilutulestik is present in the shopping cart. Currently, however, it does not seem to be able to obtain cart info. I assume that because, if I use if ( $cat_in_cart ) condition on a code, the function I use it on, does not display, even if I have a product from ilutulestik category present in the shopping cart. I've tried many different methods to obtain cart info, but none

Which Hook to alter quantity update in WooCommerce cart page?

无人久伴 提交于 2019-12-11 04:09:17
问题 I'm trying to fire a function when the quantity of a product is changed in cart. More specifically I want to run this function when a customer modify the amount in a cart. I'm looking to find the amount left in a cart then to intercept the update cart event Currently I'm using: add_action( 'woocommerce_remove_cart_item', 'my function'); When I press "update_cart", it doesn't seem to work. Any advice? Thank you! 回答1: You should use woocommerce_after_cart_item_quantity_update action hook that

Avoid a function to only runs once on button click in WooCommerce cart

邮差的信 提交于 2019-12-11 03:09:25
问题 I am trying to run function cart_refresh_update_qty every time update_cart button is clicked, but it only works the first time, if I update the cart again then it won't run again, I need to reload the page? This is is some custom code in my WordPress child themes function file. <?php // // Recommended way to include parent theme styles. // (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme) // add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function

Add the parent product name to each cart item names in WooCommerce

家住魔仙堡 提交于 2019-12-11 03:02:09
问题 I Would like to display the parent product name with child product name (cart item) in cart page, for my grouped products . I am selecting Parent product data as grouped product under linked product -> Grouped products adding child product. The code from template cart.php : echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) This is what I would like for each cart item: Parent

Custom cart item weight in Woocommerce

若如初见. 提交于 2019-12-11 02:56:37
问题 I am creating products that vary greatly in size and weight. I am not using WooCommerce product variants to help me with this as my products are heavily customized. I am using a third-party plugin to select from many variant options and I plan on checking these options to determine the products weight. The issue is I want to set the product weight before the product is added to the cart. A shipping calculator on the cart will then calculate your shipping based off your cart's total weight

How to get Quote Item Id after adding a product to cart?

寵の児 提交于 2019-12-11 02:43:57
问题 I want quote item id every time a product added to cart. I have tried many event they return the quote item object but object doesn't contain quote item id as it exists only when cart save to the db. So is there any event which will return the quote item object with quote item id? I have used following events checkout_cart_product_add_after sales_quote_add_item but it will not return quote_item_id in public function addItemToSalesModelInfo(Varien_Event_Observer $observer){ $item = $observer-

How to get product title in cart in new woocommerce 3.x

吃可爱长大的小学妹 提交于 2019-12-11 02:32:45
问题 I have this problem in a plugin, I managed to solve all errors except this one. Here is the original code... $products = WC()->cart->cart_contents; $cartTitles = ''; foreach ($products as $product) { $cartTitles .= $product['quantity'] . '-' . $product['data']->post->post_title; } I'm getting here the typical notice message - Post was called incorrectly. Properties should not be accessed directly. How can I get the post title? I tried with $product['data']->get_post() but it triggers an error

Checking that one of multiple mandatory products categories are in cart

回眸只為那壹抹淺笑 提交于 2019-12-11 01:27:33
问题 I have to check if one of my two mandatory products categories is in cart. I have customized the code from this answer: Allow checkout only when a product of a mandatory category is in cart But with my custom code, it always checks for only one of them and I get some errors. My code is not working. How can I make it work for 2 product categories instead of one? Here is the code: // Function that define the mandatory product category function your_mandatory_category_slug(){ // DEFINE HERE the

Add multiple items to a cart at the same time

对着背影说爱祢 提交于 2019-12-11 01:27:15
问题 I have the following relations : Class CartItem belongs_to :cart belongs_to :product Class Product (<=> category) has_many :cart_items Class Cart has_many :cart_items When someone adds a product to his cart, it creates a line in the CartItem table with cart.id and product.id. I can add et remove a product to a cart on the edit page, it works. But now I would like to add or remove more than one product to a cart at the same time. I just need an input number field when the customer could put

Alter calculated cart items total weight for a specific shipping class in Woocommerce

孤街浪徒 提交于 2019-12-11 00:55:32
问题 Real example: a customer had bought the following products in the cart: product A, weight: 0.2kg, Qty: 2, shipping class : FREE shipping product B, weight: 0.6kg, Qty: 3, shipping class: weight based shipping product C, weight: 0.8kg, Qty: 1, shipping class: weight based shipping My client is using a table rate shipping plugin, it can only calculate the shipping cost by using total cart contents weight, in this case it is 3.0kg. But the real chargeable weight is only 2.6kg... Had searched