Woocommerce: wc_price() - without markup - new Return-Filter

Created on 12 Jun 2014  路  1Comment  路  Source: woocommerce/woocommerce

Hi there!

The WooCommerce-function wc_price() returns the formatted price given by an argument with some Markup arround it. Would be nice to have a Return-Filter to remove this Markup,

Source:
https://github.com/woothemes/woocommerce/blob/master/includes/wc-formatting-functions.php#L303#L328

Possible Fix

  • Added Return-Filter
  • Removed extract()
  • moved price_formatting outside the $return for Return-Filter
/**
 * Format the price with a currency symbol.
 *
 * @access public
 * @param float $price
 * @param array $args (default: array())
 * @return string
 */
function wc_price( $price, $args = array() ) {
    $args = shortcode_atts(
        array(
            'ex_tax_label'  => '0'
        ),
        $args
    );

    $return          = '';
    $num_decimals    = absint( get_option( 'woocommerce_price_num_decimals' ) );
    $currency        = isset( $args['currency'] ) ? $args['currency'] : '';
    $currency_symbol = get_woocommerce_currency_symbol($currency);
    $decimal_sep     = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES );
    $thousands_sep   = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES );

    $price           = apply_filters( 'raw_woocommerce_price', floatval( $price ) );
    $price           = apply_filters( 'formatted_woocommerce_price', number_format( $price, $num_decimals, $decimal_sep, $thousands_sep ), $price, $num_decimals, $decimal_sep, $thousands_sep );

    if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $num_decimals > 0 ) {
        $price = wc_trim_zeros( $price );
    }

    $formatted_price  = sprintf( get_woocommerce_price_format(), $currency_symbol, $price );
    $return = '<span class="amount">' . $formatted_price  . '</span>';

    if ( $args[ 'ex_tax_label' ] && get_option( 'woocommerce_calc_taxes' ) == 'yes' ) {
        $return .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
    }

    return apply_filters( 'wc_price', $return, $price, $args );
}

Most helpful comment

strip_tags function from php, delete html tags:
strip_tags(wc_price($product->price))

>All comments

strip_tags function from php, delete html tags:
strip_tags(wc_price($product->price))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxrice picture maxrice  路  3Comments

richangel picture richangel  路  3Comments

starypop picture starypop  路  3Comments

joelwills picture joelwills  路  3Comments

aonzzung picture aonzzung  路  3Comments