cart

WooCommerce Cart - Dynamic Price variable pass into custom price hook

只谈情不闲聊 提交于 2019-12-01 09:13:04
I am getting the dynamic custom price in a variable that I want to pass to the hooked function in woocommerce_before_calculate_totals hook in cart. But it isn't working. This is my code: $add=200; //I want to pass this variable in add_action hook add_action( 'woocommerce_before_calculate_totals', 'add_custom_total_price'); function add_custom_total_price($cart_object) { global $woocommerce; $custom_price =$add; // This is my custom price foreach ( $cart_object->cart_contents as $key => $value ) { $value['data']->price = $custom_price; } } How can I achieve this? Thanks To make it work you just

Get the Cart shipping label and cost in Woocommerce

纵饮孤独 提交于 2019-12-01 08:07:58
I need to display the shipping cost in other side of cart page. I tried: <?php $current_shipping_cost = WC()->cart->get_cart_shipping_total(); echo $current_shipping_cost; ?> But print value nad don't title of shipping cost, because i use as title: "Express delivery with UPS 24/48 hours 4.90 euro"… How can I get order shipping cost in woocommerce? To get and display the chosen shipping method label (and other related data, if needed) in cart page (or in checkout page) : foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){ if( WC()->session->get('chosen

Add a custom product calculated price to Woocommerce cart

北战南征 提交于 2019-12-01 07:36:35
问题 In woocommerce I have added an extra text field before add to cart button to add custom charge on product purchase. This plugin will add extra text field to single product page and calculates total plus the extra charge. My problem is that I cant add custom cart totals and the extra charge add before totals I tried woocommerce_cart_calculate_fees but no luck it only show $0 in totals PHP code: /** * Check if woocommerce is active and or installed. */ if ( class_exists( 'WooCommerce' ) || in

Adding a promotional product when a certain cart amount is reached

烂漫一生 提交于 2019-12-01 05:31:39
I am looking for the right hook in WooCommerce because I need to add a promotional product to the cart when a certain cart amount of is reached, such as 100 conventional units. I have also used the hook 'init' but I do not think it's right. Here is my code: function add_free_product_to_cart(){ global $woocommerce; $product_id = 2006; $found = false; if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; if ( $_product->id == $product_id ) $found = true; } if(!$found) { $maximum = 100; $current

Auto add or remove a freebie product from cart in Woocommerce

让人想犯罪 __ 提交于 2019-12-01 04:01:45
I'm operating a WooCommerce shop, where we'd like to give every customer a freebie (e-book) that will show in the basket, after you have added a product to the basket obvious. Example: You add "product1" to the basket, and the basket will now show 2 products. the "product1" and the "freebie". When you remove the product from the basket, the freebie will be removed again. I got this code for now: add_action( 'woocommerce_add_to_cart', 'check_freebie_exists', 10, 6 ); function check_freebie_exists($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) { if($product

How to disable Cash on Delivery on some specific products in Woocommerce

巧了我就是萌 提交于 2019-12-01 02:00:48
I want to disable Cash on Delivery(COD) for some products on my online shopping site. Is it Possible? Compatible with woocommerce version 3+ Based on " Disable all payments gateway if there's specifics products in the Cart ". The code: add_filter( 'woocommerce_available_payment_gateways', 'conditionally_disable_cod_payment_method', 10, 1); function conditionally_disable_cod_payment_method( $gateways ){ // HERE define your Products IDs $products_ids = array(37,40,53); // Loop through cart items foreach ( WC()->cart->get_cart() as $cart_item ){ // Compatibility with WC 3+ $product_id = version

Auto add or remove a freebie product from cart in Woocommerce

孤人 提交于 2019-12-01 01:32:29
问题 I'm operating a WooCommerce shop, where we'd like to give every customer a freebie (e-book) that will show in the basket, after you have added a product to the basket obvious. Example: You add "product1" to the basket, and the basket will now show 2 products. the "product1" and the "freebie". When you remove the product from the basket, the freebie will be removed again. I got this code for now: add_action( 'woocommerce_add_to_cart', 'check_freebie_exists', 10, 6 ); function check_freebie

Set minimum allowed weight for a specific country in WooCommerce

这一生的挚爱 提交于 2019-12-01 01:02:50
I am trying to specifically apply a mandatory minimum weight of 20 kilos for the country of Colombia avoiding checkout if the total cart weight is under this minimal weight. Here is my actual code, that allow me to fix a minimum weight: add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' ); function cldws_set_weight_requirements() { // Only run in the Cart or Checkout pages if( is_cart() || is_checkout() ) { global $woocommerce; // Set the minimum weight before checking out $minimum_weight = 30; // Get the Cart's content total weight $cart_contents_weight = WC()->cart-

WooCommerce Price overriding not working

本小妞迷上赌 提交于 2019-12-01 00:44:04
I have set up a hidden input item using woocommerce_before_add_to_cart_button hook function add_gift_wrap_field() { ?>`<input type="hidden" id="price_val" name="added_price" value="100.34">`<?php } add_action( 'woocommerce_before_add_to_cart_button', 'add_gift_wrap_field' ); Saving fields against the product: function save_gift_wrap_fee( $cart_item_data, $product_id ) { if( isset( $_POST['added_price'] ) ) { $cart_item_data = array(); $cart_item_data[ "gift_wrap_fee" ] = "YES"; $cart_item_data[ "gift_wrap_price" ] = 100; } return $cart_item_data; } add_filter( 'woocommerce_add_cart_item_data',

WooCommerce: Cart price override with text

倖福魔咒の 提交于 2019-11-30 22:10:34
We have a bunch of products with either: No price Zero price We made them purchasable with the built-in hook but the cart still displays them as having a 0 price during checkout. We'd like the cart & checkout summary to display "Special order" or any other text, but it seems WooCommerce invalidates text-based prices. Tried this : WooCommerce: Add product to cart with price override? The above works fine with a number override, but when tried with a text override it defaults back to displaying a 0 price . Why? These products are built-to-order and the shop admin will update price after talking