Please help in logic. There is a standard function

function wc_price( $price, $args = array() ) { extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array( 'ex_tax_label' => false, 'currency' => '', 'decimal_separator' => wc_get_price_decimal_separator(), 'thousand_separator' => wc_get_price_thousand_separator(), 'decimals' => wc_get_price_decimals(), 'price_format' => get_woocommerce_price_format(), ) ) ) ); $unformatted_price = $price; $negative = $price < 0; $price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) ); $price = apply_filters( 'formatted_woocommerce_price', number_format( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator ); if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $decimals > 0 ) { $price = wc_trim_zeros( $price ); } $formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $currency ) . '</span>', $price ); $return = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>'; if ( $ex_tax_label && wc_tax_enabled() ) { $return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>'; } /** * Filters the string of price markup. * * @param string $return Price HTML markup. * @param string $price Formatted price. * @param array $args Pass on the args. * @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0. */ return apply_filters( 'wc_price', $return, $price, $args, $unformatted_price ); 

}

and it returns itself via return apply_filters ('wc_price', $ return, $ price, $ args);
Why is this not an endless loop?

    1 answer 1

    Because the filter and function are different entities, although they have the same name. In order to have an infinite loop, you need to add a filter that refers to the function itself, like this:

     add_filter( 'wc_price', 'wc_price', 10, 2 ); 

    But this is not in the code. Moreover, in general, the 'wc_price' filter is not defined in the WooCommerce code. This means that if the user does not set his filter in the theme or plugin, then the last line in the code you give will return the value of the $ return variable.

    The filter in WordPress is just a text string, a name. Different filter functions can be attached to this name, which are executed by the kernel in order of priority. If apply_filters () is called with the first parameter to which nothing is attached, the kernel will return the second parameter as the result. In your case, the $ return variable.