hook-woocommerce

Updating cart subtotal in WooCommerce

旧时模样 提交于 2020-01-04 07:36:12
问题 I want to update cart subtotal in WooCommerce. How can add action for modifying subtotal in WooCommerce? I have tried to by this code, but is not working. I would like to multiply by 12 the cart subtotal and to display this calculation on cart page. Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $total) { foreach ( $total->cart_contents as $key => $value ) { $modifiedtotal = $total->subtotal * 12; // -----------------------

Updating cart subtotal in WooCommerce

时光总嘲笑我的痴心妄想 提交于 2020-01-04 07:36:01
问题 I want to update cart subtotal in WooCommerce. How can add action for modifying subtotal in WooCommerce? I have tried to by this code, but is not working. I would like to multiply by 12 the cart subtotal and to display this calculation on cart page. Here is my code: add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $total) { foreach ( $total->cart_contents as $key => $value ) { $modifiedtotal = $total->subtotal * 12; // -----------------------

woocommerce booking status changes woocommerce order status

房东的猫 提交于 2020-01-03 15:20:50
问题 I'm using woocommerce bookings. I'm trying to trigger woocommerce order status to refund if the woocommerce_booking status is cancelled. I tried this code but it's not working. global $woocommerce; $order = new WC_Order( $order_id ); if ( 'cancelled' == $order->status ) { $order->update_status('refund', 'order_note'); } 回答1: To update order status on cancel status add_action('woocommerce_cancelled_order','change_status_to_refund', 10, 1); function change_status_to_refund($order_id) { $order =

Add a button after add to cart and redirect it to some custom link in WooCommerce

余生颓废 提交于 2020-01-03 07:18:07
问题 I am adding a button after add to cart button using this hook: add_action( 'woocommerce_after_add_to_cart_button', array($this, 'add_button')); But when I click on that button it is doing the functionality of add to cart button. How to customize that button link (to some other page) ? Thanks in advance. 回答1: You need to use woocommerce_after_add_to_cart_button hook this way to get what you are expecting: add_action( 'woocommerce_after_add_to_cart_button', 'add_custom_button', 10, 0 );

Make checkout addresses fields not required in WooCommerce

佐手、 提交于 2020-01-03 06:01:29
问题 In Woocommerce I am trying to make checkout adresses fields not required with the code below… But I've got this error "Please enter an address to continue", when submitting checkout form. My code to set adresses checkout fields not required: add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 ); function wc_npr_filter_phone( $address_fields ) { $address_fields['billing_phone']['required'] = true; $address_fields['billing_country']['required'] = false; $address_fields[

Sorting priority for specific Woocommerce checkout fields depending on country

核能气质少年 提交于 2020-01-03 03:38:09
问题 In Woocommerce, I need to set the default ordering priority (sorting) of three fields on the checkout page: The first change depends on the choice of the 'IT' country code: postcode - 'priority' => 91, The other two are free of conditions, I just need to set the default priority: billing_email - 'priority' => 30, billing_phone - 'priority' => 40, By editing the file directly, class-wc-countries.php core file as shown below, I get what I need. But clearly at each update of the plugin I lose

Add account email conditionally on Customer processing Order email notification in Woocommerce

♀尐吖头ヾ 提交于 2020-01-03 03:21:06
问题 So this is more of my solution here but I wanted to open this up to see if the community could find a better alternative or potentially find use for this solve. Our client asked us for the following alteration to the email order receipts received on order creation: The receipts should go to the account holder and cc the billing email if it's different As we know Woocommerce by default sends the order receipt (Customer Processing) based on only the set billing_email on checkout so I started to

Hide Related Products from specific products single pages in Woocommerce

馋奶兔 提交于 2020-01-02 15:51:48
问题 Okay so I am trying to hide the 'Related Products' section on the product page, BUT only for a specific product not all products. I have found the following documentation to hide the section for all product pages: https://docs.woocommerce.com/document/remove-related-posts-output/ But as I mentioned this is how to hide the 'Related Products' section on all product pages. But I am looking for a way to hide this section ONLY on a specific product page. Does anyone have any idea on how this can

Save the sum of all specific order item custom fields as order meta data in WooCommerce

怎甘沉沦 提交于 2020-01-02 08:02:44
问题 Following my previous question " Save WooCommerce order item custom fields sum as a new meta data" , when an order is placed, some order item custom meta data quantity , assemblycost and calculated_field (which value is to quantity x assemblycost ) are saved. How can I save as custom order meta data the sum of all order items calculated_field values? For example, a sample order would look like so: Product A: assemblycost: 10 quantity: 2 calculated_field: 20 Product B: assemblycost: 15

Save the sum of all specific order item custom fields as order meta data in WooCommerce

◇◆丶佛笑我妖孽 提交于 2020-01-02 08:01:33
问题 Following my previous question " Save WooCommerce order item custom fields sum as a new meta data" , when an order is placed, some order item custom meta data quantity , assemblycost and calculated_field (which value is to quantity x assemblycost ) are saved. How can I save as custom order meta data the sum of all order items calculated_field values? For example, a sample order would look like so: Product A: assemblycost: 10 quantity: 2 calculated_field: 20 Product B: assemblycost: 15