Set cart item price from a hidden input field custom price in Woocommerce 3

Update 2021 – Handling custom price item in mini cart First for testing purpose we add a price in the hidden input field as you don’t give the code that calculate the price: // Add a hidden input field (With a value of 20 for testing purpose) add_action( ‘woocommerce_before_add_to_cart_button’, ‘custom_hidden_product_field’, 11 ); function custom_hidden_product_field() { … Read more

Set product sale price programmatically in WooCommerce 3

The hook woocommerce_get_sale_price is deprecated since WooCommerce 3 and replaced by woocommerce_product_get_sale_price. Also Product displayed prices are cached. When sale price is active, regular price is also active. Try this instead: // Generating dynamically the product “regular price” add_filter( ‘woocommerce_product_get_regular_price’, ‘custom_dynamic_regular_price’, 10, 2 ); add_filter( ‘woocommerce_product_variation_get_regular_price’, ‘custom_dynamic_regular_price’, 10, 2 ); function custom_dynamic_regular_price( $regular_price, $product ) … Read more

Replace the Variable Price range by the chosen variation price in WooCommerce 4+

Update March 2021 (Works at least from WooCommerce 3.7 up to 5+) The code: add_action(‘woocommerce_before_add_to_cart_form’, ‘selected_variation_price_replace_variable_price_range’); function selected_variation_price_replace_variable_price_range(){ global $product; if( $product->is_type(‘variable’) ): ?><style> .woocommerce-variation-price {display:none;} </style> <script> jQuery(function($) { var p = ‘p.price’ q = $(p).html(); $(‘form.cart’).on(‘show_variation’, function( event, data ) { if ( data.price_html ) { $(p).html(data.price_html); } }).on(‘hide_variation’, function( event ) { … 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