cart

Apply automatically a coupon based on specific cart items count in Woocommerce

那年仲夏 提交于 2019-11-29 17:13:16
I am trying to automatically trigger a coupon to be applied in the cart specifically for when there are 4 items in the cart. The coupon is pre-created in the Woocommerce back-end of the site "tasterbox" I am using an amended version from this answer code: Add WooCommerce coupon code automatically based on product categories Here is my code version: add_action( 'woocommerce_before_calculate_totals', 'wc_auto_add_coupons', 10, 1 ); function wc_auto_add_coupons( $cart_object ) { // Coupon code $coupon = 'tasterbox'; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Initialising variables

Set cart item product generated sale price only for specific products in Woocommerce

假装没事ソ 提交于 2019-11-29 16:56:09
Following Set only specific products sale price programmatically in WooCommerce 3 , the related cart items price are not updated with the product's generated sale price. How can I get the generated sale price for specific products, in the related cart items? Any help is appreciated. To get the right generated sale price in cart item for specific product IDs try the following: // HERE below in the array set your specific product IDs function specific_product_ids(){ return array(37, 41); // <=== <=== <=== <=== Your Product IDs } // Generating dynamically the product "regular price" add_filter(

Cart item discount based on quantity in Woocommerce 3

谁说我不能喝 提交于 2019-11-29 16:39:07
My WP site sells customized t-shirts. The customization plugin makes each customized shirt a line item in the woocommerce cart. If there are 2 shirts ordered of one design (quantity of 2 on that line item) I want to discount. But if there is just 1 item per line I dont want to discount. I found this solution Adding a discount by cart items conditionally based on the item quantity But this seems to change the product price in the db, so after the discount kicks in for say 2 blue shirts because there were 2 ordered on 1 line, if I add a 3rd shirt on a separate line it also gets the discount,

WooCommerce login redirect based on cart

ε祈祈猫儿з 提交于 2019-11-29 16:32:53
I want to apply following 2 case : If User not logged in and cart is empty: Then redirect user to login and then my account If User not logged in and cart has product: Then redirect user to login and after login redirect to checkout My Code : function wpse_Nologin_redirect() { if ( ! is_user_logged_in() && (is_checkout()) ) { // feel free to customize the following line to suit your needs $MyLoginURL = "http://example.in/my-account/"; wp_redirect($MyLoginURL); exit; } } add_action('template_redirect', 'wpse_Nologin_redirect'); Above code is working fine for my first case. But for my second

Change cart items weight to update the shipping costs in Woocommerce

与世无争的帅哥 提交于 2019-11-29 16:21:19
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 ) { foreach ( $cart->cart_contents as $cart_item_key => $values ) { $_product = $values['data']; //very

WooCommerce - Adding a custom price to each product in cart

孤人 提交于 2019-11-29 16:19:31
I would like to update the price of products adding a custom price in cart using this simple piece of code update_post_meta( $product->id, '_regular_price', $frame_price_added); . Note: what I'm trying to achieve is to add this custom price to each product in cart. I have try to get $frame_price_added this way: $frame_price = $res['_number_field'][0]; $frame_price_added = $product->price + $frame_price; Here $product->price is price coming from woocomerce product and $frame_price is coming from my newly added price. I was wondering how do I associate this new price to cart, because it doesn't

magento 1.8 add product to cart using php

元气小坏坏 提交于 2019-11-29 15:46:08
问题 Up until Magento 1.7 I was able to use the following code to add a product to cart programatically: require_once '../app/Mage.php'; Mage::getSingleton('core/session', array('name' => 'frontend')); umask(0); Mage::app(); $session = Mage::getSingleton('customer/session'); $product = Mage::getModel('catalog/product')->load(99); // Random product ID // get cart and add product $cart = Mage::getSingleton('checkout/cart'); $cart->init(); $cart->addProduct($product, 1); // update session $session-

Limit the number of cart items in Woocommerce

徘徊边缘 提交于 2019-11-29 15:21:21
问题 I am using Woocommerce and need the following: As product is being sold to another country and that country's customs only allow a total quantity of 6, so I need to prevent customers from order more than 6 items (products). 6 is the total of items or products. Customer can order 1 product in quantity of 6 or 2 products with quantity of 3 each. Customs will only allow a total number of items to be 6. If there are more then 6 items in the cart, a warning should appear and prevent customer from

Remove attribute values from product variation title and show them on separate rows

爷,独闯天下 提交于 2019-11-29 15:01:19
I have a checkout page where I want to: Remove selected product attribute values from product variation title item. Remove the quantity from item title too. Display the different product attribute value such as size, color and the quantity on different rows, for this product variation item. I want to display on my checkout page: Aria Sport Shorts (the product title) Color: Dusty Pink Size: Small QTY: 1 Instead of this: Is it possible? Where I should start to make this real? UPDATED 1) Since WooCommerce 3+, to remove attribute values from Product variation title and to display them in a

Shopping Cart Rules with Custom Condition?

醉酒当歌 提交于 2019-11-29 14:53:38
问题 I have made a coupon [coupon_code = SWIMFREE] if category is swimming equipment and hobby is swimming will be discount by 50%. and now I have problem about 3 steps checkout. Here's the description ... Checkout Cart : to apply to coupon First Step : Shipping and Billing Address Second Step : Pick your Hobby (has another sales_flat_quote table , sales_flat_quote_hobby ) Final Step : Checkout->Overview What i wanted is : when the coupon applied and the hobby is swimming, the third step changing