How to Add Prefix in Front of WooCommerce Product Price

Viewing 0 reply threads
  • Author
    Posts
    • Avatar photoDan
      Keymaster
        #2056

        Here’s my version of the code that adds a prefix to the price of products in Woocommerce.

        /* Woo Price Prefix */
        add_filter( 'woocommerce_get_price_html', 'woo_price_prefix' );
        function woo_price_prefix($price) {
        if (!empty($price)) {
        $prefix_before_price = 'Price: ';
        return $prefix_before_price . $price ;
        }}

        The code goes into the functions.php file of your selected WordPress theme.

        There are many published variants of the code that adds the prefix, but they are usually missing the “if (!empty($price))” part. Omitting it results in the prefix appearing in front of the place where the price should be even when the price for the product is not set at all. So on products without the price you get “Price:     “. The “if (!empty($price))” removes the prefix in that case.

    Viewing 0 reply threads
    Reply To: How to Add Prefix in Front of WooCommerce Product Price
    Your information: