cart

WooCommerce Cart Quantity Base Discount

跟風遠走 提交于 2019-11-28 11:25:51
In WooCommerce, how do I set a cart discount based on the total number of items in the cart? For example: 1 to 4 items - no discount 5 to 10 items - 5% 11 to 15 items - 10% 16 to 20 items - 15% 21 to 25 items - 20% 26 to 30 items - 25% I've search internet but not found any solution or plugins available. Thanks. LoicTheAztec You can use a negative cart fee to get a discount. Then you will add your conditions & calculations to a acustom function hooked in woocommerce_cart_calculate_fees action hook, this way: ## Tested and works on WooCommerce 2.6.x and 3.0+ add_action( 'woocommerce_cart

Add a fee for a specific product category in Woocommerce

狂风中的少年 提交于 2019-11-28 10:44:00
问题 I already found this code here and it works for like 80/90% for me (see below). This code adds 60 euro to my cart when there is a product from category ID 349 in the cart. When I add a product from that category to my cart when the cart is empty it works fine. But when there is already a product in my cart from a different category and then I add the product with category 349 it doesn't add the 60 euro extra fee. How is this possible? function woo_add_cart_fee() { $category_ID = '349'; global

GET a coupon code via URL and apply it in WooCommerce Checkout page [closed]

痞子三分冷 提交于 2019-11-28 10:21:31
I have a WooCommerce website and when customer add-to-cart a product, it is get redirected to checkout page, so cart page is not accessible. I would like to apply coupon via URL ( GET ) on checkout page, with something like https://example.com/?coupon_code=highfive . When customer click this URL then the coupon code is stored in browser sessions. Then if he add-to-cart any product then the coupon is applied into checkout page. Is this possible? Update 3: This can be done in a very simple way with the following 2 hooked functions: The first one will catch the coupon code in the Url and will set

Change cart items weight to update the shipping costs in Woocommerce

社会主义新天地 提交于 2019-11-28 06:06:41
问题 I am creating a very particular type of e-shop using Woocommerce and Extra Product Options plugin and I am facing a problem with the weights of the products. I want to modify the weight of each product inside the cart , depending on the selected attribute, without luck. I am using this to alter the weight without any success. add_action( 'woocommerce_before_calculate_totals', 'add_custom_weight', 10, 1); function add_custom_weight( WC_Cart $cart ) { if ( sizeof( $cart->cart_contents ) > 0 ) {

How to retrieve cart_item_data with WooCommerce?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:03:10
During the add_to_cart function, there is a filter to add "cart item data". The filter is woocommerce_add_cart_item_data . I expected to store my custom plugin data in this, so that the data is stored relative to the item and multiple products can be added with different data. This all seemed to work, but I am not able to retrieve the data. I can't figure it out. The data is there , I can see it in a serialized string, but I can't pull it out. echo '<pre>'; var_dump( WC() ); foreach( WC()->cart->get_cart() as $cart_item ) { var_dump( $cart_item ); var_dump( WC()->cart->get_item_data( $cart

Add tax free fees to WooCommerce cart programmatically

不羁的心 提交于 2019-11-28 04:58:27
问题 I try to add fees based on some calculations I do on Woocommerce cart, but I want to exclude it from VAT. This is my code: function woo_add_cart_fee( $cart ) { global $woocommerce; $bookable_total = 0; foreach(WC()->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; //doing my stuff to calculate $fee variable WC()->cart->add_fee( 'Fees: ', $fee, false, '' ); //WC()->cart->add_fee( 'Fees: ', $fee, true, '' ); //WC()->cart->add_fee( 'Fees: ', $fee, false, 'zero rate'

Dynamic shipping fee based on custom radio buttons in Woocommerce

徘徊边缘 提交于 2019-11-28 02:09:44
In Woocommerce, I have added two custom radio buttons on the checkout page and on click, I called an ajax function to add a delivery fee. Here is my code: $(document).on('change','#shipping_method_0_local_pickup5',function(e) { $('.woocommerce-shipping-fields').css({ 'display': 'none' }); $("#deli").css("display","block"); var selected = $("input[type='radio'][name='post-del']:checked"); var selectedVal = selected.val(); var pickurl= "<?php echo admin_url('admin-ajax.php');?>?action=delivery"; $.ajax({ url: pickurl, type: "POST", data:{ input:selectedVal, }, success: function(responseText) {

Changing WooCommerce cart item names

孤街浪徒 提交于 2019-11-28 01:44:06
问题 The goal is to change the name of the item as it gets passed to our payment gateway, but leave it as-is for display on our product pages. I've tried this in my functions.php: function change_item_name( $item_name, $item ) { $item_name = 'mydesiredproductname'; return $item_name; } add_filter( 'woocommerce_order_item_name', 'change_item_name', 10, 1 ); But it doesn't seem to be working for me. I feel like I should be passing in an actual item ID or something… I'm a little lost. Any information

Checking products in cart based on category name woocommerce?

∥☆過路亽.° 提交于 2019-11-27 22:29:26
问题 I'm trying to trigger an echo statement if a certain category of product is in my cart, here's my code: <?php //Check to see if user has product in cart global $woocommerce; //flag no book in cart $item_in_cart = false; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; $terms = get_the_terms( $_product->id, 'product_cat' ); foreach ($terms as $term) { $_categoryid = $term->term_id; } if ( $_categoryid == 'name_of_category' ) { //book is in

WooCommerce: Check if items are already in cart

别等时光非礼了梦想. 提交于 2019-11-27 21:26:57
问题 I found this great snippet from this website The following is the function to check if a specific product exists in cart: function woo_in_cart($product_id) { global $woocommerce; foreach($woocommerce->cart->get_cart() as $key => $val ) { $_product = $val['data']; if($product_id == $_product->id ) { return true; } } return false; } And this to use anywhere needed: if(woo_in_cart(123)) { // Product is already in cart } The problem is how to use it to check multiple products like this: if(woo_in