cart

WooCommerce Cart - Dynamic Price variable pass into custom price hook

三世轮回 提交于 2019-12-19 09:56:39
问题 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

Adding a promotional product when a certain cart amount is reached

痴心易碎 提交于 2019-12-19 07:51:51
问题 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 =

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

心已入冬 提交于 2019-12-19 05:09:42
问题 I want to disable Cash on Delivery(COD) for some products on my online shopping site. Is it Possible? 回答1: 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

Adding a notice on Cart and checkout page based on item custom field highest value

三世轮回 提交于 2019-12-19 04:16:05
问题 I have a a custom field value for each product. This custom field is inserted with the code below : <?php // Insert a Custom Admin Field add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); function woo_add_custom_general_fields() { echo '<div class="options_group">'; woocommerce_wp_text_input( array( 'id' => 'days_manufacture', 'label' => __( 'Days for Manufacture', 'woocommerce' ), 'placeholder' => '', 'description' => __( 'Insert here',

WooCommerce Price overriding not working

邮差的信 提交于 2019-12-19 04:14:11
问题 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

Magento override controller

我们两清 提交于 2019-12-19 02:47:14
问题 I would like to do the above. Ive overridden many files in the past...block, model, helper....but this one eludes me. Can anyone see what im doing wrong here: (ive edited this code...to include some of the recomendations now...) Heres my folder structure (2 controller locations as a test): /Idigital/Idgeneral/etc/config.xml /Idigital/Idgeneral/controllers/Checkout/CartController.php /Idigital/Idgeneral/controllers/CartController.php Heres my config.xml: <?xml version="1.0"?> <config> <modules

Redirect Magento to checkout onepage after adding item to cart

前提是你 提交于 2019-12-18 17:37:14
问题 How can I redirect the user after it adds one item to the cart? lets say I want him to choose one item and go to the checkout/onepage, how can I do that? 回答1: You could create an observer listening for the checkout_cart_add_product_complete event and in there you could do something like the following public function addToCartComplete(Varien_Event_Observer $observer) { // Send the user to the Item added page $response = $observer->getResponse(); $request = $observer->getRequest(); $response-

Woocommerce add to cart ajax and mini-cart

好久不见. 提交于 2019-12-18 16:53:07
问题 I need to re-populate mini-cart when product added via ajax add to cart. I manage to update cart quantity with filter woocommerce_add_to_cart_fragments like this: add_filter( 'woocommerce_add_to_cart_fragments', function($fragments) { ob_start(); ?> <div class="cart-contents"> <?php echo WC()->cart->get_cart_contents_count(); ?> </div> <?php $fragments['div.cart-contents'] = ob_get_clean(); return $fragments; } ); And my HTML markup is <div class="cart-contents"> <?php echo WC()->cart->get

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

谁说胖子不能爱 提交于 2019-12-18 09:26:13
问题 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. 回答1: 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); //

WooCommerce login redirect based on cart

邮差的信 提交于 2019-12-18 09:14:19
问题 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