Вы можете увидеть вот как сообщение представлено и меняется при изменении количества:
https://thefabricboutique.co.uk/product ... nen-blend/
Добавьте 0,5 метра за 6,25 фунтов стерлингов
Я хотел бы знать, как изменить это на следующий код:
Добавьте 1 единицу на 0,5 метра (6,25 фунта стерлингов за 0,5 метра)
Таким образом, просто добавьте «Добавить 1 единицу» (при этом 1 меняется по мере изменения количества)И кронштейны по цене. В котором есть дублированная функция изменения счетчика из первой части.
Код: Выделить всё
add_action( 'woocommerce_before_add_to_cart_quantity', 'display_product_total_amount_html' );
function display_product_total_amount_html() {
global $product;
if( ! has_term( array('fabric'), 'product_cat', $product->get_id() ) ) return;
$metres_per_qty = 0.5;
$display_price = wc_get_price_to_display($product);
$formatted_price = ''. number_format($display_price, 2) . '';
// Output product total price amount
$price_string = sprintf( __('Add %s for %s', 'woocommerce'),
'' . $metres_per_qty . ' metre',
str_replace('0.00', $formatted_price, wc_price(0)) );
// Output product total price amount
echo ''.$price_string.''
?>
jQuery(function($){
$('input[name=quantity]').on( 'input change', function(){
const qty = $(this).val();
if ( qty != 0 ) {
const lengthTxt = qty > 2 ? ' metres' : ' metre';
$('.total-price_qty .price-amount').html( parseFloat( * qty).toFixed(2) );
$('.total-price_qty .qty-metres').html( parseFloat( * qty)+lengthTxt );
}
});
});
Подробнее здесь: [url]https://stackoverflow.com/questions/78517173/display-formated-product-total-and-mesurements-based-on-quantity-in-woocommerce[/url]
Мобильная версия