Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Created September 11, 2017 06:14
Show Gist options
  • Select an option

  • Save kreamweb/428af31704cbaf96a3e9969a27d366d1 to your computer and use it in GitHub Desktop.

Select an option

Save kreamweb/428af31704cbaf96a3e9969a27d366d1 to your computer and use it in GitHub Desktop.
Calculate total only of shipping products
<?php
add_filter('ywcm_cart_total','ywcm_cart_total');
function ywcm_cart_total( $total ){
$total = 0;
if ( ! empty( WC()->cart->cart_contents ) ) {
foreach ( WC()->cart->cart_contents as $cart_item_key => $values ) {
if ( $values['data']->needs_shipping() ) {
$total += $values['line_total'];
}
}
}
return $total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment