apply_filters( 'lp__price_html', $price, $sale_price, $args );
This code filters and customizes the HTML structure for price.
Plugin
Namespace
Launchpad
Parameters
float
$price
Regular price
float
$sale_price
Sale price
array
$args
Price HTML arguments
Return
string
Filtered price HTML arguments
Example
/**
* Define a callback function to customize the HTML structure for price
*
* @param string $html HTML representation of the price
* @param float $price Regular price
* @param float $sale_price Sale price
* @param array $args Price HTML arguments
* @return string Filtered HTML representation of the price
*/
function custom_price_html( $html, $price, $sale_price, $args ) {
// Modify the $html as per your requirements
$modified_html = '<span class="custom-price">' . $html . '</span>';
// You can also modify $price, $sale_price, and $args here if needed
return $modified_html;
}
// Add the filter hook for customizing the HTML structure for price
add_filter( 'lp__price_html', 'custom_price_html', 10, 4 );
In this example:
- We’ve defined a callback function
custom_price_htmlthat takes the HTML representation of the price, regular price, sale price, and price HTML arguments as parameters. - Inside the callback function, we’ve modified the
$htmlvariable to wrap it in a<span>element with a custom class. - You can also modify
$price,$sale_price, and$argswithin the callback function if needed. - We then use
add_filterto hook our callback function to the “lp__price_html” filter. This associates our callback with the specific filter hook for customizing the HTML structure for price.