您将要使用hooks and filters 要改变这一点。我会看看woocommerce_get_price_html
和/或woocommerce_variable_price_html
过滤器。
编辑:
以下是您需要更改的核心WC代码:
/**
* Format a sale price for display.
*
* @since 3.0.0
* @param string $regular_price Regular price.
* @param string $sale_price Sale price.
* @return string
*/
function wc_format_sale_price( $regular_price, $sale_price ) {
$price = \'<del>\' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . \'</del> <ins>\' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . \'</ins>\';
return apply_filters( \'woocommerce_format_sale_price\', $price, $regular_price, $sale_price );
}
如您所见,返回值上有一个过滤器。您想要做的是挂接到该过滤器中,并返回您想要的价格。类似这样:
add_filter(\'woocommerce_format_sale_price\', \'wc_override_sale_price_format\', 10, 2);
function wc_override_sale_price_format( $regular_price, $sale_price ) {
$price = \'<ins>\' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . \'</ins> <del>\' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . \'</del>\';
return $price;
}