cart

Allow only one product category in cart at once in Woocommerce

╄→гoц情女王★ 提交于 2020-01-06 02:46:04
问题 How would I go about configuring the Woocommerce cart to only allow one product category type in it at a time? 回答1: The following code will allow adding to cart only items from one product category avoiding add to cart and displaying a custom notice: add_filter( 'woocommerce_add_to_cart_validation', 'only_one_product_category_allowed', 20, 3 ); function only_one_product_category_allowed( $passed, $product_id, $quantity) { // Getting the product categories term slugs in an array for the

Add a custom field value as a cart non taxable fee in Woocommerce

社会主义新天地 提交于 2020-01-05 07:01:14
问题 I have a custom field in checkout that adds a price to cart. $woocommerce->cart->add_fee($price_info['label'], $fee, $taxable, $tax_class); Everything works fine. But how do i make it non taxable ? 回答1: To make a fee non taxable you need to set the 3rd argument to false, so your code will be: WC()->cart->add_fee( $price_info['label'], $fee ); The default value for the 3rd argument is false , so no taxable. See its source code: /** * Add additional fee to the cart. * * @uses WC_Cart_Fees::add

Percentage discount only on not in-sale items subtotal in Woocommerce

回眸只為那壹抹淺笑 提交于 2020-01-05 04:12:06
问题 There is an excellent answer for discount based on not-in-sale items count but If there is one item-in-sale in the list it's not working for all other not-in-sale items... My question is: How can I make discount only to the "items not in sale" when I have "items in sale" in the same cart list? 回答1: Updated - Try this instead: add_action('woocommerce_cart_calculate_fees' , 'custom_cart_discount', 20, 1); function custom_cart_discount( $cart ){ if ( is_admin() && ! defined( 'DOING_AJAX' ) )

Woocommerce Booking - Get a specific value from “Data” Cart item object

假装没事ソ 提交于 2020-01-05 03:52:06
问题 I have this array, that is dumped from WooCommerce using these lines: $items = $woocommerce->cart->get_cart(); foreach($items as $item => $values) { // some code here… } If I make a raw output of my cart ($items) and I get this: ["f584d8671586d336d84e8cf9ed43303c"]=> array(11) { ["booking"]=> array(15) { ["_year"]=> int(2016) ["_month"]=> int(8) ["_day"]=> int(28) ["_persons"]=> array(1) { [0]=> int(1) } ["_date"]=> string(9) "2016-8-28" ["date"]=> string(13) "28 août 2016" ["_time"]=> string

Woocommerce set minimum order for a specific user role

纵然是瞬间 提交于 2020-01-05 03:04:10
问题 I have a php code that sets a 100 minimum order site wide, that works good. I want to set a different minimum order of 250 for a specific role 'company' using the same code or by cloning it and wrapping it in an if() statement, only I have no idea how to write it. Would appreciate any kind of help. This it the currant code (don't mind the Hebrew text, its just the error messages, when the condition is not met): // Set a minimum dollar amount per order add_action( 'woocommerce_check_cart_items

Updating cart subtotal in WooCommerce

旧时模样 提交于 2020-01-04 07:36:12
问题 I want to update cart subtotal in WooCommerce. How can add action for modifying subtotal in WooCommerce? I have tried to by this code, but is not working. I would like to multiply by 12 the cart subtotal and to display this calculation on cart page. Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $total) { foreach ( $total->cart_contents as $key => $value ) { $modifiedtotal = $total->subtotal * 12; // -----------------------

Updating cart subtotal in WooCommerce

时光总嘲笑我的痴心妄想 提交于 2020-01-04 07:36:01
问题 I want to update cart subtotal in WooCommerce. How can add action for modifying subtotal in WooCommerce? I have tried to by this code, but is not working. I would like to multiply by 12 the cart subtotal and to display this calculation on cart page. Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $total) { foreach ( $total->cart_contents as $key => $value ) { $modifiedtotal = $total->subtotal * 12; // -----------------------

Add a button after add to cart and redirect it to some custom link in WooCommerce

余生颓废 提交于 2020-01-03 07:18:07
问题 I am adding a button after add to cart button using this hook: add_action( 'woocommerce_after_add_to_cart_button', array($this, 'add_button')); But when I click on that button it is doing the functionality of add to cart button. How to customize that button link (to some other page) ? Thanks in advance. 回答1: You need to use woocommerce_after_add_to_cart_button hook this way to get what you are expecting: add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );

Display shipping methods to frontend as in the admin panel?

◇◆丶佛笑我妖孽 提交于 2020-01-03 03:22:09
问题 In WooCommerce, I'm doing the form of adding / changing product (at the front-end). I need to display the fields for changing the cost of delivery of the installed methods as in the admin panel. How can I do it? Here is my actual code: <form> <!-- Various input fields --> <?php foreach ($shipping_methods as $method) { ?> <lebel> <h3><?php echo $method ?></h3> <input type="number" value="<?php //hook for input - output to make changes of shipping price of this method??Which one ?>"> </lebel> <

Auto add a Product to Cart in Woocommerce 3

主宰稳场 提交于 2020-01-02 21:59:08
问题 I would like that anybody who visits my Woocommerce shop finds a free product in his cart. I found this code and it works but it shows many php errors in logs. Do you have an idea why is not "clean"? Any help on this please. /* * AUTOMATICALLY ADD A PRODUCT TO CART ON VISIT */ function aaptc_add_product_to_cart() { if ( ! is_admin() ) { $product_id = 99999; // Product Id of the free product which will get added to cart $found = false; //check if product already in cart if ( sizeof( WC()->cart