• I want to show the fee amount right below the normal price of the product on the product page. What is the php code (or another solution) to achieve this?

    Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • If you wish to show the flat fee amount below the unit price and only for simple products here is the code:

    function change_simple_product_price_display( $price_html, $product ) {
      if ( is_product() ) {
    	if ( $product->is_type( 'simple' ) ) {
    	  $flat_fee = get_post_meta( $product->get_id(), 'product-fee-amount', true );
    	  if ( ! empty( $flat_fee ) ) {
    		$price_html = $price_html . '<br>' . __('+ One Time Charges (excl. VAT):', 'Your Domain') . ' ' . wc_price($flat_fee);
    	  }
    	}
      }
      return $price_html;
    }
    add_filter( 'woocommerce_get_price_html', 'change_simple_product_price_display', 10, 2 );

    If you wish to show the flat fee for all your products, then you need to remove the if ( $product->is_type( ‘simple’ ) ) part of the code.

    • This reply was modified 6 years, 8 months ago by ittspiritgr.
    • This reply was modified 6 years, 8 months ago by ittspiritgr.

    You seem to use some kind of volume/bulk discount plugin. Perhalps the plugin overwrites the woocommerce_get_price_html filter.
    I suggest to try to disable volume/bulk discount functionality and check if the code is working.
    Also check your other plugins to varify that they do not override the woocommerce_get_price_html filter.
    Note: The code I wrote above is applicable to fees that are used as one-time-charges.

    If your fees are fixed (do not vary) for each one of your products you can inject additional details in any part for the product page.
    For instance you can show your fees below the product title and price part as follows:

    add_action( 'woocommerce_single_product_summary', 'show_additional_product_details', 20 );
    function show_additional_product_details() {
      global $product;
      if ( is_product() ) {
        $flat_fee = get_post_meta( $product->get_id(), 'product-fee-amount', true );
        if ( !empty( $flat_fee ) ) {
          echo __('+ One Time Charges (excl. VAT):', 'Your Domain') . ' ' . wc_price($flat_fee);
        }
      }
    }
    Thread Starter Kevinn02

    (@kevinn02)

    This one works!

    Is it possible to wrap the text in a div?

    You can at will add in your echo statement the html code you wish. Don’t forget to use ‘.’ as string concatenation operator. For instance, the code below shows the one-time charges wrapped in a div and shows in bold the title (+ One Time Charges (excl. VAT):):
    echo '<div><strong>' . __('+ One Time Charges (excl. VAT):', 'Your Domain') . ' </strong>' . wc_price($flat_fee) . '</div>;

    • This reply was modified 6 years, 8 months ago by ittspiritgr.

    For your convenience, all the strings I am echoing are translation ready as I use the following call:
    __( string $text, string $domain = 'default' )

    hellow, one question, in wich php file i should paste the code?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Product fee below price on product page’ is closed to new replies.