Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4

Updated Since Woocommerce version 3, woocommerce_checkout_create_order_line_item action hook now replace outdated woocommerce_add_order_item_meta hook in a much better way using the new introduced CRUD getters and setters methods: // Save custom data to order item meta data add_action( ‘woocommerce_checkout_create_order_line_item’, ‘tshirt_order_meta_handler’, 20, 4 ); function tshirt_order_meta_handler( $item, $cart_item_key, $values, $order ) { $custom_designer = WC()->session->get( $cart_item_key.’_designer’ ); … Read more

Change WooCommerce default password security level

The only existing hook setting for that is woocommerce_min_password_strength filter hook. So you can set a custom hook function and lowering this strenght. There is 4 possible settings: 3 => Strong (default) 2 => Medium 1 => Weak 0 => Very Weak (anything). Here is that code: add_filter( ‘woocommerce_min_password_strength’, ‘reduce_min_strength_password_requirement’ ); function reduce_min_strength_password_requirement( $strength ) … Read more

Set custom shipping rates programmatically in Woocommerce 3

As this is a filter and as the data is cached, you can’t get any output with print_r(). The correct way to make it work is the following: add_filter( ‘woocommerce_package_rates’, ‘custom_shipping_costs’, 20, 2 ); function custom_shipping_costs( $rates, $package ) { // New shipping cost (can be calculated) $new_cost = 1000; $tax_rate = 0.2; foreach( $rates … Read more

Customize addresses fields on WooCommerce My account and Checkout

The hook woocommerce_checkout_fields only allow customizations on checkout page and will not affect the My account “Addresses” section fields. The following will affect both My account “Addresses” section fields and checkout fields, allowing to make billing and shipping fields customized also on the related my account section. 1) For addresses fields (both billing and shipping) … Read more

Display custom order meta data value in email notifications WooCommerce

You have some minor mistakes, via the if condition “$email->id == …” you can target the mails How to target other WooCommerce order emails ‘customer_completed_order’ ‘customer_processing_order’ ‘customer_on_hold_order’ ‘customer_refunded_order’ ‘customer_reset_password’ ‘customer_invoice’ ‘customer_new_account’ ‘customer_note’ ‘cancelled_order’ ‘failed_order’ ‘new_order’ function woocommerce_email_order_invoice_number( $order, $sent_to_admin, $plain_text, $email ) { // For ‘new order’ if ( $email->id == ‘new_order’ ) { // … Read more

Adding custom field to product category

You can add custom fields to WooCommerce product category by using following action : product_cat_add_form_fields product_cat_edit_form_fields edited_product_cat create_product_cat UPDATED on 17-Feb-2017 ###For WP version 4.4 and above. As of WordPress 4.4, update_term_meta() and get_term_meta() functions have been added. This means that now we don’t have to save the data in wp_options table anymore, rather they … Read more

Add a new custom field to WooCommerce checkout and display on admin order pages and email notifications

You’re using delivery_date, city_custom & Citymixed up, this gives you different values, so that is your problem // Display a custom checkout select field after Billing form add_action( ‘woocommerce_after_checkout_billing_form’, ‘my_custom_checkout_field’, 10, 1 ); function my_custom_checkout_field( $checkout ) { echo ‘<div id=”my_custom_checkout_field”> ‘ . __(‘City’) . ”; woocommerce_form_field( ‘city_custom’, array( ‘type’ => ‘select’, ‘options’ => array( … Read more

Allow re-sending New Order Notification in WooCommerce 5+

Since WooCommerce 5.0 a new filter hook has been added, that disables resending “New Order” email notification, restricting this specific notification to be sent only one time. This is what has been added to WC_Email_New_Order trigger() method (default is set to false): /** * Controls if new order emails can be resend multiple times. * … Read more

Display the discounted percentage near sale price in Single product pages for WC 3.0+

Updated – 2019 (avoid rounding price issue) – 2017 (avoid NAN% percentage value) woocommerce_sale_price_html hook has been replaced by a different hook in WooCommerce 3.0+, that has now 3 arguments (but not the $product argument anymore). add_filter( ‘woocommerce_format_sale_price’, ‘woocommerce_custom_sales_price’, 10, 3 ); function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) { // Getting the clean numeric prices … Read more

How to add custom stock status to products in WooCommerce 4+

Last update: 04/22 – Tested in WordPress 5.9.2 & WooCommerce 6.3.1 Code goes in functions.php file of the active child theme (or active theme). Use woocommerce_product_stock_status_options instead of woocommerce_product_options_stock_status. This way you can immediately add a status instead of replace the existing dropdown Also use woocommerce_get_availability_text & woocommerce_get_availability_class opposite woocommerce_get_availability. This way you don’t have … Read more