Update div with additional attributes on cart update
-
Hello! I have two additional attributes in my Woocommerce cart. On first load it works well, but I need to refresh the div on cart updated. I have no idea how to do this. Please help!
My function below:
add_action(‘woocommerce_cart_collaterals’, ‘myprefix_cart_extra_info’);
function myprefix_cart_extra_info() {
$ves = 0;
$packmax = 0;// Iterating though each item in cart
$cart_items = WC()->cart->get_cart();
foreach( $cart_items as $cart_item ){
$item_id = $cart_item[‘product_id’];
$terms = get_the_terms( $item_id , ‘pa_ves-g’);
foreach($terms as $key => $term)
if(!empty($term->name)) $ves += $term->name * $cart_item[“quantity”];
$termspack = get_the_terms( $item_id , ‘pa_obem-vlozheniya’);
if(!empty($termspack))
foreach($termspack as $termpack)
if(!empty($termpack->name)) $packmax += $termpack->name * $cart_item[“quantity”];
}
if ($ves > $packmax)
echo ‘<p class=”overloaded”>Слишком много наполнения!</p>’;
echo ‘<div class=”cart-extra-info”>’;
echo ‘<p class=”total-weight”>’ . __(‘Общий вес наполнения:’, ‘woocommerce’);
echo ‘ ‘ . $ves . ‘ ‘ . ‘ г’;
echo ‘</p>’;
echo ‘<p class=”total-pack_max”>’ . __(‘Максимальный вес вложения:’, ‘woocommerce’);
echo ‘ ‘ . $packmax . ‘ ‘ . ‘ г’;
echo ‘</p>’;
echo ‘</div>’;
}
- The topic ‘Update div with additional attributes on cart update’ is closed to new replies.