function displaying_cart_items_weight( $item_data, $cart_item ) {
// Product quantity
$product_qty = $cart_item[‘quantity’];
// Calculate total item weight
$item_weight = $cart_item[‘data’]->get_weight() * $product_qty;
$item_data[] = array(
‘key’ => __(‘Weight’, ‘woocommerce’),
‘value’ => $item_weight,
‘display’ => $item_weight . ‘ ‘ . get_option(‘woocommerce_weight_unit’)
);
return $item_data;
}
add_filter( ‘woocommerce_get_item_data’, ‘displaying_cart_items_weight’, 10, 2 );
function wcw_cart() {
global $woocommerce;
if ( WC()->cart->needs_shipping() ) : ?>
<tr class=”shipping”>
<th><?php _e( ‘Peso’, ‘woocommerce-cart-weight’ ); ?></th>
<td><span class=”label”><?php echo $woocommerce->cart->cart_contents_weight . ‘ ‘ . get_option( ‘woocommerce_weight_unit’ ); ?></span></td>
</tr>
<?php endif;
}
add_action( ‘woocommerce_cart_totals_after_order_total’, ‘wcw_cart’ );
add_action( ‘woocommerce_review_order_after_order_total’, ‘wcw_cart’ );
function register_text( $translated ) {
$translated = str_ireplace(‘Register’, ‘Registar’, $translated);
return $translated;
}
add_filter( ‘gettext’, ‘register_text’ );
add_filter( ‘ngettext’, ‘register_text’ );
function my_free_shipping_notice() {
// Elimina cualquier condición si solo quieres que aparezca el aviso en un único punto, o modifícalo a tu gusto para que aparezca en más sitios.
if ( ! is_cart() && ! is_checkout() ) {
return;
}
$packages = WC()->cart->get_shipping_packages();
$package = reset( $packages );
$zone = wc_get_shipping_zone( $package );
$cart_total = WC()->cart->get_displayed_subtotal();
if ( WC()->cart->display_prices_including_tax() ) {
$cart_total = round( $cart_total – ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() );
} else {
$cart_total = round( $cart_total – WC()->cart->get_discount_total(), wc_get_price_decimals() );
}
foreach ( $zone->get_shipping_methods( true ) as $k => $method ) {
$min_amount = $method->get_option( ‘min_amount’ );
if ( $method->id == ‘free_shipping’ && ! empty( $min_amount ) && $cart_total < $min_amount ) {
$remaining = $min_amount – $cart_total;
// Añadimos el aviso. Modica el texto a tu gusto 🙂
wc_add_notice( sprintf( ‘Atenção! A partir de 30 euros tem direito a portes grátis 😊’, wc_price( $remaining ) ) );
}
}
}
add_action( ‘wp’, ‘my_free_shipping_notice’ );