Check if a user/guest has purchased specific products in WooCommerce

Lighter and improved code version in HERE that handle multiple product IDs Updated (compatibility for Woocommerce 3+) Yes it’s possible, writing a conditional function that returns “true” if current customer has already bought specifics defined products IDs. This code goes on function.php file of your active child theme or theme. Here is the conditional function: … Read more

Woocommerce: Which hook to replace deprecated “woocommerce_add_order_item_meta”

2017/2018 THE RIGHT WAY (Using new CRUD setters and Getters methods) Related: Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4 Since woocommerce 3 that has improved many things making drastic changes, the action hook woocommerce_add_order_item_meta still work perfectly even in woocommerce version 3.3+. This hook is enabled by WC_Checkout class methods and related functions in the checkout … Read more

Change product prices via a hook in WooCommerce 3+

Update (December 2020) 2 code versions for themes and plugins (works in Woocommerce 3.3.x too) Cached variations prices in Woocommerce 3 (Update and addition): Now using woocommerce_get_variation_prices_hash filter hook much more efficient, instead of wc_delete_product_transients()… See this related thread Added product price filter widget hooks (see at the end). 1) Plugin version with a constructor … Read more

Create programmatically a WooCommerce product variation with new attribute values

Update January 2020: Changed to WC_Product method get_name() instead of get_title() Update September 2018: Handling taxonomy creation (Thanks to Carl F. Corneil) From a defined variable product ID You will find below, a custom function that will add (create) a Product variation. The variable parent product needs to have set for it the needed attributes. … Read more

Replace the Variable Price range by the chosen variation price in WooCommerce 3

2021 definitive update Works for WooCommerce 4+ and 5+ available on: Replace the Variable Price range by the chosen variation price in WooCommerce 4+ Update (December 2017): to avoid, Problems regarding non variable products in some themes and a repetition availability bug in some themes Note: Some plugins like the German Market or some themes … Read more

WooCommerce action hooks and overriding templates

First in reference below you will find how to override properly woocommerce templates via a theme (avoiding editing the plugin templates). In your first code snippet, as you can see for woocommerce_single_product_summary hook, you have in order all the different templates that are @hooked in this hook location with do_action() WordPress function: do_action( ‘woocommerce_single_product_summary’ ); … Read more

Change cart item prices in Woocommerce 3

Update 2021 (Handling mini cart custom item price) With WooCommerce version 3.0+ you need: To use woocommerce_before_calculate_totals hook instead. To use WC_Cart get_cart() method instead To use WC_product set_price() method instead Here is the code: // Set custom cart item price add_action( ‘woocommerce_before_calculate_totals’, ‘add_custom_price’, 1000, 1); function add_custom_price( $cart ) { // This is necessary … Read more