Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    What code do you have right now? There are different hooks for each product type’s price html.

    Thread Starter rafix

    (@rafix)

    This seems to work for the products that do have it.

    /**
     * @snippet       Disable Variable Product Price Range
     * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
     * @sourcecode    https://businessbloomer.com/disable-variable-product-price-range-woocommerce/
     * @author        Rodolfo Melogli
     * @compatible    WooCommerce 2.4.7
     */
    
    add_filter( 'woocommerce_variable_sale_price_html', 'bbloomer_variation_price_format', 10, 2 );
    
    add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format', 10, 2 );
    
    function bbloomer_variation_price_format( $price, $product ) {
    
    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'vanaf %1$s <small class="woocommerce-price-suffix">excl. BTW</small>', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
    // Sale Price
    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
    sort( $prices );
    $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'vanaf %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
    if ( $price !== $saleprice ) {
    $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
    }
    return $price;
    }
    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Thread Starter rafix

    (@rafix)

    We have the option checked with:

    ({price_including_tax} incl. BTW)

    Or are you recommending to remove previous code and place with this?
    As I believe no suffix will be shown anymore then.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    I’m suggesting your remove your code and add a suffix via that settings field, as that applies to all prices then.

    Thread Starter rafix

    (@rafix)

    The code supports texts at the product like:

    ( 'vanaf %1$s <small class="woocommerce-price-suffix">excl. BTW</small>'

    We’d like these to stay, I removed the code and seen what happend. But then it doesn’t show the custom lines we do want there. How would or should we change the code. To keep those there, and have the simple product show the suffix as well.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    if you hover the tooltip it shows you what placeholders you can insert if you need a price shown there?

    Otherwise if you must go the custom code route, use this filter for simple products https://hookr.io/filters/woocommerce_price_html/

    Thread Starter rafix

    (@rafix)

    It shows i can add two placeholders, however we want the text to be shown which is custom added. We cannot do this through the suffix part in woocommerce?

    I’ve tried the custom route. I went into the functions.php, there I added the following:

    // define the woocommerce_price_html callback
    function filter_woocommerce_price_html( $price, $instance ) {
        // make filter magic happen here...
        return $price;
    };
    
    // add the filter
    add_filter( 'woocommerce_price_html', 'filter_woocommerce_price_html', 10, 2 );

    Then I went to the /includes/abstracts/abstract-wc-product.php file and added under rule 957 the following line:

    $price = apply_filters( 'woocommerce_price_html', $price, $this );

    However this doesn’t seem to give any result in the website. what am I doing wrong?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    You don’t need to edit core files. Filters work without that.

    woocommerce_price_html is already in that file.

    Thread Starter rafix

    (@rafix)

    So where do I need to place these then. Only in the functions file? can you be a bit more detailed? on which and where to edit these in so it will hopefully work ??

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    functions.php is where your snippet could go. Or within a custom plugin.

    Thread Starter rafix

    (@rafix)

    Hi Mike,

    This did not seem to do anything, I added the snippet into the functions.php right above the other suffix. However.. No result. Is there anything else we could try? Maybe you could try this for us?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Thread Starter rafix

    (@rafix)

    Hi Mike,

    Thank you for helping me out so much. However this filter already is in the code and doesn’t catch the suffix at the simple product.

    Any more options we can try out, to get the suffix to appear?

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    @rafix show me code.

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Price suffix at simple product’ is closed to new replies.