Я хочу изменить отображение цен на странице корзины для категорий «курица» и «говядина» на вес (за килограмм).
Для страницы корзины:
add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' );
// Change the cart prices with $price variable and weight amount
function wb_change_product_price_cart( $price, $product ) {
$product_categories = array('chicken', 'beef');
if( has_term( $product_categories, 'product_cat', $product->get_id() ) ){
$price = $price . ' per kg'; // change weight measurement here
return $price;
}
}
А также на странице оформления заказа категории «курица» и «говядина» должны быть указаны по весу (за килограмм). Для страницы оформления заказа:
add_filter( 'woocommerce_checkout_cart_item_quantity', 'wb_checkout_review', 10, 3 );
// Change the checkput prices with $cart_item variable and weight amount
function wb_checkout_review ( $quantity, $cart_item, $cart_item_key ) {
$product_categories = array('chicken', 'beef');
if( has_term( $product_categories, 'product_cat', $product->get_id() ) ){
$cart_item = ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . ' kg </strong>'; // change weight measurement here
return $cart_item;
}
}
У меня пустая страница, когда я ввожу эти коды ... Не могли бы вы мне помочь?