Answer the question
In order to leave comments, you need to log in
What is the best way to display text in the shopping cart depending on the product or shipping class?
I want to check the availability of goods with a certain delivery class in the cart and, depending on whether it is or not, display text. If there is this delivery class, output one text, if it is not there, then another.
add_action('woocommerce_cart_display_variable_text' , 'print_text_based_by_cart');
function print_text_based_by_cartt(){
$class_slug = 'food-stock';
foreach( WC()->cart->get_cart() as $cart_item ){
if( $cart_item['data']->get_shipping_class() == $class_slug ){
echo 'span>Текст 1 </span>';
}
else{
echo 'span>Текст 2 </span>
<span>Текст 3 </span>';
}
}
}
<div class="cart_totals__item">
<?php
do_action('woocommerce_cart_display_variable_text');
?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question