Код: Выделить всё
add_filter( 'woocommerce_get_price_html', 'get_trade_pricing_html', 10, 2 );
function get_trade_pricing_html( $price_html, $product ) {
$trade_price = get_post_meta( $product->get_id(), '_trade_price', true );
if ( ! empty( $trade_price ) ) {
$formatted_trade_price = wc_price( $trade_price );
$price_html = sprintf( '%s', $formatted_trade_price );
}
return $price_html;
}
< /code>
В Frontend:
В идеале, хотя у меня был бы дополнительный параметр, доступный так:
Код: Выделить всё
function get_trade_pricing_html( $price_html, $product, $customer_type ) {
if ( $customer_type === 'trade' ) {
$trade_price = get_post_meta( $product->get_id(), '_trade_price', true );
if ( ! empty( $trade_price ) ) {
$formatted_trade_price = wc_price( $trade_price );
$price_html = sprintf( '%s', $formatted_trade_price );
}
}
return $price_html;
}
< /code>
позволяет мне использовать это в моих шаблонах:
Очевидно, что это невозможно, так как get_price_html - предопределенная функция, которую нельзя перепрофировать, но я все еще хотел бы найти способ обойти эту проблему. Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/796 ... custom-fie