xioten
Forum Replies Created
-
Forum: Plugins
In reply to: [Weight Based Pricing for WooCommerce] Show always price per KiloHi,
Thanks a lot, it’s work perfect !
For people looking for change suffix by /kg or else :
Add following code inside function.php (child theme)
Statically :
add_filter('wbp_wc_price_html', function($html_with_unit, $original_html) { $original_html .= ' /kg'; return $original_html; }, 10, 2);
Or dynamically with custom field, I did this way :
1 – First we add custom field inside product page :
add_action('woocommerce_product_options_general_product_data', function() { woocommerce_wp_text_input([ 'id' => '_suffix_price', 'label' => __('Suffix', 'txtdomain'), ]); });
2 – Secondly, we need to save data :
add_action('woocommerce_process_product_meta', function($post_id) { $product = wc_get_product($post_id); $suf_price = isset($_POST['_suffix_price']) ? $_POST['_suffix_price'] : ''; $product->update_meta_data('_suffix_price', sanitize_text_field($suf_price)); $product->save(); });
3 – Then, we need to display it :
add_filter('wbp_wc_price_html', function($html_with_unit, $original_html) { global $post; $product = wc_get_product($post->ID); if (!empty($product->get_meta('_suffix_price'))) { $suf_price = $product->get_meta('_suffix_price'); $original_html .= ' /'.$suf_price; return $original_html; } }, 10, 2);
Hope this is help,
Thanks again for your update,
Regards- This reply was modified 2 years, 5 months ago by xioten.
Forum: Plugins
In reply to: [Weight Based Pricing for WooCommerce] Show always price per KiloHi,
Thanks for your awesome plugin ??
Actually, I wanted to ask the same question. I did it using custom field but I need to remove the addPriceSuffix function inside Product Adjustments, because currently I have this : 12€/kg/g
I tried this :
remove_filter('woocommerce_get_price_html', array('ProductAdjustments', 'addPriceSuffix'), 99, 2);
and else.But nothing happen or I get an error
Fatal error: Uncaught Error: Class ‘ProductAdjustments’ not found in…
There is a way to remove that function ?
Thanks by advance,
Regards