cart

Hide and unhide a specific shipping methods based on shipping class in WooCommerce

余生颓废 提交于 2019-12-08 03:03:24
i have a cart that has three method standard delivery(0-10kg), standard delivery(11-20kg) and next day delivery(0-20kg), my problem is when i a product with a frozen food shipping class to the cart the shipping method should only be the next day delivery and if there is now shipping class on the cart it only has the standard delivery, my problem is when a add the product with a shipping class and a products with no shipping class it will not go to the condition that i make. add_filter( 'woocommerce_package_rates', 'custom_hide_shipping_methods', 10, 2 ); function custom_hide_shipping_methods(

Checking cart items for a product category in Woocommerce

怎甘沉沦 提交于 2019-12-07 23:08:26
问题 In woocommerce, I'm trying to check in cart items for a particular product category using: add_action('woocommerce_before_cart', 'fs_check_category_in_cart'); function fs_check_category_in_cart() { // Set $cat_in_cart to false $cat_in_cart = false; // Loop through all products in the Cart foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $product = $cart_item['data']; echo '<pre>',print_r($product),'</pre>'; // If Cart has category "download", set $cat_in_cart to true if (

Adding a custom text under the X button that removes items from cart

…衆ロ難τιáo~ 提交于 2019-12-07 20:51:58
问题 With Wordpress and WooCommerce, I am trying to add a custom text "delete item" under the "x" in the shopping cart tthat removes items from cart. I tried to "inspect element" to find where this "x" text icon was located, but I am hitting a brick wall. Any suggestions on how I can find this, and amend the "x" button to include text underneath? Thanks. 回答1: add_filter('woocommerce_cart_item_remove_link', 'remove_icon_and_add_text', 10, 2); function remove_icon_and_add_text($string, $cart_item

Custom cart item counts by product category in Woocommerce 3

▼魔方 西西 提交于 2019-12-07 17:17:28
I am trying to display the Woocommerce cart count by product category. I have two categories: " protein " and " pantry " I want to display the count by item category. So if there are 2 protein and 4 pantry, I want those two item category counts to be displayed next to each other, updating with ajax. e.g. the final look would say: PROTEIN 2 in cart and PANTRY 4 in cart (depending on the amount of item types in the cart) I have found this snippet here which displays the cart count for a given category, but I am having trouble displaying it on the web page correctly. Currently It just displays

Remove the stock quantity from WooCommerce cart error messages

喜欢而已 提交于 2019-12-07 11:19:43
问题 Iin WooCommerce, I've set woocommerce->settings->products->inventory->stock display format to "Never show quantity remaining in stock" . However if a customer ads a product to the cart, continues to cart or checkout page and enter a value higher than we have in stock they get this error message: Sorry, we do not have enough " {product_name} " in stock to fulfill your order ( {available_stock_amount} in stock). Please edit your cart and try again. We apologize for any inconvenience caused.

Add a percentage discount based on customer total purchases sum in Woocommerce

旧城冷巷雨未停 提交于 2019-12-07 11:02:26
问题 In Woocommerce, I would like to set a percentage discount based on customer total purchases sum. For example if the total purchase sum greater or equal to 200$ , customer get 5% discount . So, I have first part of code for showing the total sum: function get_customer_total_order() { $customer_orders = get_posts( array( 'numberposts' => - 1, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_type' => array( 'shop_order' ), 'post_status' => array( 'wc-completed' ) ) );

add product to cart with custom options

≯℡__Kan透↙ 提交于 2019-12-07 09:31:56
问题 I have to create a (virtual, simple )product and then add to cart both programmatically, i have done this so far. now i have to set custom options when this product add to cart. but nothing happens . here is my code $product = Mage::getModel('catalog/product')->load($product_id); $cart = Mage::getModel('checkout/cart'); $cart->init(); $params = array( 'product' => $product->getId(), // This would be $product->getId() 'qty' => 1, 'options' => array( 34 => "value", 35 => "other value", 53 =>

Set a calculated price for variable products in the WooCommerce

£可爱£侵袭症+ 提交于 2019-12-07 09:23:24
问题 In Woocommerce, I use custom fields to calculate the price of a product, based on this code - Add custom fields to custom product calculated price in Woocommerce. Thanks for the help LoicTheAztec. // Add a custom field before single add to cart add_action( 'woocommerce_before_add_to_cart_button', 'custom_product_price_field', 5 ); function custom_product_price_field(){ echo '<div class="custom-text text"> <h3>Rental</h3> <label>Start Date:</label> <input type="date" name="rental_date" value="

WooCommerce cannot access cart from product class

此生再无相见时 提交于 2019-12-07 08:42:20
问题 I have a custom WooComerce product type, and I need to access the cart url from within it. Would seem simple enough: class WC_Product_My_Product extends WC_Product_Simple { public function some_method() { global $woocommerce; $href = $woocommerce->cart->get_cart_url(); } } However: Fatal error: Call to a member function get_cart_url() on a non-object What can possibily be wrong? Is the $woocommerce variable not available when defining a custom product class? If so, is there some internal

Magento: add product twice to cart, with different attributes!

送分小仙女□ 提交于 2019-12-07 07:55:00
问题 I have been working with this for a whole day but i cannot find any solution: I have a product (lenses), which has identical attributes, but user can choose one attribute set for one eye and another attribute set for another. On the frontend I got it ok, see it here. So the user can select attributes for left or right eye, but it is the same product. I build a function, which should take a product in a cart (before save), add other set of attributes, so there should be two products in the