Home › Forums › WoodMart support forum › Free product in cart
Free product in cart
- This topic has 7 replies, 2 voices, and was last updated 19 hours, 17 minutes ago by Hung Pham.
-
AuthorPosts
-
November 19, 2024 at 5:36 pm #613505
dweb360ParticipantHello
For internal management reasons; I have to add a free product to the cart each time a customer buy a product.
This is done via :function add_free_product_with_two_items() { // Define the ID of the free product $free_product_id = 20320; // Replace with your actual product ID // Set the minimum number of products required to trigger the free gift $minimum_product_count = 1; // Retrieve cart items $cart = WC()->cart->get_cart(); // Initialize variables $non_free_product_count = 0; $free_product_exists = false; // Loop through each item in the cart foreach ($cart as $cart_item) { // Check if the item is not the free product if (!isset($cart_item['custom_price'])) { // Count non-free products $non_free_product_count++; } else { // Check if the free product is already in the cart $free_product_exists = true; } } // If the conditions are met, add the free product to the cart if ($non_free_product_count >= $minimum_product_count && !$free_product_exists) { WC()->cart->add_to_cart($free_product_id, 1, 0, array(), array('custom_price' => 0)); } } // Hook the function to the WooCommerce calculation add_action('woocommerce_before_calculate_totals', 'add_free_product_with_two_items');
How to hide product and price and quantity from the cart?
Thank you
Attachments:
You must be logged in to view attached files.November 20, 2024 at 1:28 pm #613756
Hung PhamKeymasterHi dweb360,
Thanks for reaching to us.
Please add the below Custom CSS code to Theme Settings > Custom CSS > Global Custom CSS:
.product_list_widget>li>a.cart-item-image, .product_list_widget .cart-info span.quantity{ display: none; }
Regards,
November 20, 2024 at 1:32 pm #613761
dweb360ParticipantHello,
Thank you for the code but I need to remove images … only for this particular product not for all products in the cart.
Thank youNovember 20, 2024 at 5:44 pm #613915
Hung PhamKeymasterHi dweb360,
Please remove previous code and use below one:
.product_list_widget>li> a[data-product_id="20320"] + a.cart-item-image, .product_list_widget .cart-info span.quantity{ display: none; }
Regards,
November 20, 2024 at 7:32 pm #613971
dweb360ParticipantHello
Thank you for the code, working on the cart but not on the side cart.
Thank youNovember 21, 2024 at 10:01 am #614076
Hung PhamKeymasterHi dweb360,
Please provide URL of the mentioned page, so I can take a closer look.
Regards,
November 21, 2024 at 12:39 pm #614215
dweb360ParticipantHello
https://www.gourmandisedeluxe.com/NEW/
Thank youNovember 22, 2024 at 4:03 pm #614737
Hung PhamKeymasterHi dweb360,
I checked your site and saw that thumbnails and other details have been removed as you wanted https://ibb.co/vwGjy5C
Let me know if you resolved.
Regards,
-
AuthorPosts
- You must be logged in to create new topics. Login / Register