Open chunkysteveo opened 6 years ago
This quick hack added to a theme will allow the min price to function as a custom "advanced" field which then adds in the expected custom field _wc_measurement_price_calculator_min_price.
Front end seems to function normally with this in place now. But this is a messy hack and needs a real solution, ideally minimum prices per variation, as some variations will be more costly than others, so a minimum price may vary depending on the variable chosen. A single min price would be a minimum requirement if individual variation minimum prices is not possible.
`add_action( 'woocommerce_product_options_advanced', 'wc_measurement_price_calculator_product_minimum_price_hack' );
function wc_measurement_price_calculator_product_minimum_price_hack() { woocommerce_wp_text_input( array( 'id' => '_wc_measurement_price_calculator_min_price_hack', 'wrapper_class' => 'show_if_pricing_calculator', 'class' => 'wc_input_price short', / translators: Placeholders: %s - currency symbol / 'label' => sprintf( ( 'HACK IF VARIABLE! Minimum Price (%s)', 'woocommerce-measurement-price-calculator' ), get_woocommerce_currency_symbol() ), 'type' => 'number', 'custom_attributes' => array( 'step' => 'any', 'min' => '0', ), 'description' => ( 'This is a HACK to allow min price to follow through if the product is a variable. Currently the plugin does not have minimum prices for variations.', 'woocommerce' ) ) ); }
add_action( 'woocommerce_process_product_meta', 'wc_measurement_price_calculator_product_minimum_price_save_hack',100,1 );
function wc_measurement_price_calculator_product_minimum_price_save_hack( $post_id ) { if ( isset( $_POST['_wc_measurement_price_calculator_min_price_hack'] ) ) { update_post_meta( $post_id, '_wc_measurement_price_calculator_min_price', $_POST['_wc_measurement_price_calculator_min_price_hack'] ); update_post_meta( $post_id, '_wc_measurement_price_calculator_min_price_hack', $_POST['_wc_measurement_price_calculator_min_price_hack'] ); } }`
Were put the code?
functions.php
A heartfelt thanks from Italy!
If you have a simple product, and use the price calculator option to allow users to set e.g. width and height - you can set the minimum price of the product, works great. If you have a variable product with the price calculator option - the variations do not have a field to enter a minimum price.
It would be good to either have a minimum price per variable variation, or keep the minimum price global value? I see there was a fix in 3.12.3 "When a minimum price is set on a Simple Product before switching to a Variable Product, the minimum price setting remains active, but is no longer visible or editable until switching back to Simple Product" This would actually be useful to have/enabled?
Steve