cart

Calculated distance shipping cart fee via Google API in WooCommerce

老子叫甜甜 提交于 2019-12-10 11:04:41
问题 So, I have written a piece of code after getting some help from SO and internet. I want to add a fees to the cart by calculating the distance between the vendor's location ( billing_city ) and customer's area via Google Maps API Distance-Matrix . Here, I use a dropdown after billing form to get the area of customer. I am having problem of getting the value from cookies and pass the variable to next function. FYKI, I have inserted this code into my child theme functions. add_action( 'wp_footer

Tax class “Zero rate” per user role on specific product ID's

泄露秘密 提交于 2019-12-10 10:24:23
问题 I got this code that will apply tax free on a user role regardless of what they order, which is fine. But now I need another user role that will apply tax free on specific products id , and I'm not sure how to acomplish that. The code im using right now for tax free on all products for specific user role is: // Apply a different tax rate based on the user role. function wc_diff_rate_for_user( $tax_class, $product ) { // Getting the current user $current_user = wp_get_current_user(); $current

Dynamically calculate product price based on custom fields values when added-to-cart

大兔子大兔子 提交于 2019-12-10 06:58:14
问题 I found the code to add existing product: global $woocommerce; $woocommerce->cart->add_to_cart(16); But I need to add product, with price that determined by 2 inputs: Age Quality I calculate the product's price by the formula age*quality. I know it's possible to add product with variations, but it's so many possible variations. Is it possible to set the product price dynamically based on custom fields calculation values? Thanks 回答1: For the cart items (when product is added-to cart), is

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

爱⌒轻易说出口 提交于 2019-12-09 08:09:21
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 { echo 'Not in cart!'; } } } add_action('woocommerce_before_shop_loop_item', 'find_product_in_cart The

Hide shipping methods for specific shipping classes in WooCommerce

帅比萌擦擦* 提交于 2019-12-08 12:23:17
问题 In WooCommerce, I am hiding shipping methods based on different shipping classes in cart using "Hide shipping methods for specific shipping class in WooCommerce" answer code (the 2nd way) , but the problem is that I use WPML plugin which manage 2 languages site, so looking for just one class won't do it. So I need to handle 2 shipping classes instead of one. I tried addind 2 shipping classes this way: // HERE define your shipping classes to find $class = 3031, 3032; But it breaks the website.

PHP Passing Value on Cart

空扰寡人 提交于 2019-12-08 11:00:09
问题 I have created a shopping cart page using PHP. Now the problem I encountered was that, when I add a product to the cart from the product list, what happens is that only the 1st product on the list is added. When I add another product (since every product on the list has it's own Add to Cart button), the 1st product is added again. Doesn't matter what item I choose, it still end up with the 1st product being added. Am I missing something? Here's my code: Product List: <?php do { ?> <tr> <td

Display a product custom field value in WooCommerce cart and checkout table

不想你离开。 提交于 2019-12-08 10:38:14
问题 In WooCommerce and I have added a custom field "description" for each product. I was able to find a way to show both, the label name and the value: add_filter( 'woocommerce_add_cart_item_data', 'save_days_field', 10, 2 ); function save_days_field( $cart_item_data, $product_id ) { $special_item = get_post_meta( $product_id , 'description',true ); if(!empty($special_item)) { $cart_item_data[ 'description' ] = $special_item; // below statement make sure every add to cart action as unique line

Change wc_cart_totals_shipping_method_label function in Woocommerce

青春壹個敷衍的年華 提交于 2019-12-08 09:08:44
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 = ! $has_cost && in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true );

Apply a discount only on the second cart item in Woocommerce

喜你入骨 提交于 2019-12-08 07:51:18
问题 How to get and modify price of the second item in my cart ? I want to made discount -3% on the second product (items in cart already sorted by the price, highest top). I think it must calculate in woocommerce_before_calculate_totals or like discount in woocommerce_cart_calculate_fees ? Thanks 回答1: Updated (Added compatibility with Woocommerce 3+) For a product item is better to use woocommerce_before_calculate_totals action hook: add_action( 'woocommerce_before_calculate_totals', 'discount_on

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

南笙酒味 提交于 2019-12-08 06:51:00
问题 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(