Hi,
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.