• Hi,

    I let my costumers set the purchased quantity in grams (g). But I would like to show te price per kilo (kg) on the price that is shown below the product name. Is it possible?

    Thank you in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ThemeParrot

    (@themeparrot)

    Hi,

    Thank you for raising a request.

    At the moment, it is not possible to convert/show Grams(g) to Kilogram(kg)

    We are happy to tell you that the feature (weight unit conversion) is on our road map, and will add this feature in our upcoming releases. Thanks for your suggestion, it helps us assist you better.

    Thanks
    Themeparrot Team

    Hi,

    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

    • This reply was modified 2 years, 5 months ago by xioten.
    • This reply was modified 2 years, 5 months ago by xioten.
    • This reply was modified 2 years, 5 months ago by xioten.
    Plugin Author ThemeParrot

    (@themeparrot)

    Hi,

    Thank for reaching out.

    Also, thank you for your patience.

    We have introduced a new event “wbp_wc_price_html” in our recent release (1.1.3) to handle scenarios as per your requirement.

    Can you update our plugin and have a check?

    Also, we suggest you to use the following snippet to remove weight unit from price html:
    https://gist.github.com/ananthatstar/2f8f7baf37d17bbbb919567f6e8f5bd6

    Hope this helps.

    Kindly have a check on the same via your end and let us know in case of any further queries.

    Thanks
    Themeparrot Team

    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.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show always price per Kilo’ is closed to new replies.