cart

Set cart item price from a hidden input field custom price in Woocommerce 3

浪尽此生 提交于 2019-12-08 06:46:03
问题 In Woocommerce, I used jQuery to calculate a custom price on a single product pages, and now need to pass this value to the cart. The desired behavior is to pass the new price retrieved from the hidden field to the cart item price. Here is my actual code: // Hidden input field in single product page add_action( 'woocommerce_before_add_to_cart_button', 'custom_hidden_product_field', 11, 0 ); function custom_hidden_product_field() { echo '<input type="hidden" id="hidden_field" name="custom

Remove duplicated shipping packages using a shipping class in Woocommerce

岁酱吖の 提交于 2019-12-08 06:18:47
问题 The products in my website are handled by one of that 2 shipping plugins: Printful Integration for WooCommerce and Printify for WooCommerce Shipping. when there is mixed items from each shipping plugin. Those plugins split each one the shipping package in two when there is mixed items (which is a a conflict and a problem) . So I have added a shipping class 'printful' (which id is 548 ) to the products that are handled by the Printful plugin, and tried to adjust Hide shipping method for

Hide a specific Woocommerce products from loop if they are in cart

痴心易碎 提交于 2019-12-08 05:53:44
问题 I'm trying to write a hook that hides a specific product from the shop page if it's in the cart, but I can't seem to figure out two things. function find_product_in_cart() { $hide_if_in_cart = array(6121, 6107, 14202, 14203); $in_cart = false; foreach( WC()->cart->get_cart() as $cart_item ) { $product_in_cart = $cart_item['product_id']; foreach ( $hide_if_in_cart as $key => $value ) { if ( $product_in_cart === $value ) { $in_cart = true; } } if ( $in_cart ) { echo 'Product in cart'; } else {

Disable WooCommerce Payment methods if cart item quantity limit is reached

天大地大妈咪最大 提交于 2019-12-08 05:21:07
问题 Is there a way or filter to disable selective payment methods if cart quantity increase more than "X number of items" example "15"? I know we can limit max number of quantity before adding to cart but I want to disable some payment methods only. Thanks 回答1: You can use a custom function hooked in woocommerce_available_payment_gateways filter hook. You will have to set inside it your quantity limit and your payment methods slugs. Here is that code: add_filter('woocommerce_available_payment

Cart products dissapear on refresh page Prestashop

好久不见. 提交于 2019-12-08 05:15:46
问题 since some weeks I have a problem with my Prestashop 1.4.0.12 When I add a product to cart, ajax works correctly and add the product very well. But, if I change page, or sometimes adding a product, the cart change deleting all products on refresh a new page. Sometimes I can move within some pages, but dissapears the products of the cart and later if I have a new cart returns to the old cart. Anybody knows about it? I think that the problem is on id_guest but I need to know if anyone have some

Custom cart item counts by product category in Woocommerce 3

∥☆過路亽.° 提交于 2019-12-08 05:08:35
问题 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

Change wc_cart_totals_shipping_method_label function in Woocommerce

心不动则不痛 提交于 2019-12-08 05:02:50
问题 Inside Woocommerce plugin on the includes subfolder, there's a file wc-cart-functions.php . I would like to change the function wc_cart_totals_shipping_method_label() , but I am not allowed to copy the function to my theme's functions.php. I believe I have to use a custom action/filter to change this core function, but no idea how to do that. Original function: function wc_cart_totals_shipping_method_label( $method ) { $label = $method->get_label(); $has_cost = 0 < $method->cost; $hide_cost =

Change Cart total using Hooks in Woocommerce 3.2+

a 夏天 提交于 2019-12-08 04:00:09
问题 I want to add 300 to order total on woocommerce checkout page but woocommerce_calculate_totals hook doesn't do the job... If I use var_dump($total), I see the correct result - int(number), but the total amount in order table is not changing. add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 ); function action_cart_calculate_totals( $cart_object) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; if ( !WC()->cart->is_empty() ): $total = $cart_object->cart

Allow only one product per product category in cart

我是研究僧i 提交于 2019-12-08 03:13:26
On this Question / Answer I have found the PHP code about how to just add one product per category in cart in Woocommerce. The code works just fine, but I want to add the latest added product to cart and if there is already a product of that category in the cart, I want to have the oldest deleted. add_filter( 'woocommerce_add_to_cart_validation', 'custom_checking_product_added_to_cart', 10, 3 ); function custom_checking_product_added_to_cart( $passed, $product_id, $quantity) { // HERE Type your alert displayed message // $message = __( 'BLA BLA YOUR MESSAGE.', 'woocommerce' ); $product_cats

How to find out product id from “woocommerce_cart_item_removed” hook?

…衆ロ難τιáo~ 提交于 2019-12-08 03:09:46
问题 I have code add_action( 'woocommerce_cart_item_removed', 'after_remove_product_from_cart' ); function after_remove_product_from_cart($removed_cart_item_key, $instance) { $product_id = $removed_cart_item_key['product_id']; } I want to find out a way to get product id or actual product object itself using $removed_cart_item_key. How do you do it? I cannot find any references, thanks. 回答1: should be something like this... add_action( 'woocommerce_cart_item_removed', 'after_remove_product_from