Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

Woocommerce integration

Home / Forums / Virtue Theme / Woocommerce integration

This topic is: Resolved
[Resolved]
Posted in: Virtue Theme
March 13, 2018 at 9:45 am

Hi there!

I’m using Woocommerce with Virtue Premium and am attempting to add a snippet of code to my site which will allow me to hide particular shipping methods from the Woocommerce cart, when specific shipping classes appear in there.

The code I have works when listing a single shipping method, eg. [‘flat_rate:13’]

However I have 3 other methods that I’d like to add and I’m unsure of how to list them.

They are: [‘flat_rate:14’] [‘flat_rate:15’] and [‘flat_rate:22’]

Here is the code that is currently works for hiding [‘flat_rate:13’]

add_filter( ‘woocommerce_package_rates’, ‘hide_shipping_when_class_is_in_cart’, 10, 2

);

function hide_shipping_when_class_is_in_cart( $rates, $package ) {
// shipping class IDs that need the method removed
$shipping_classes = array(892,897,1143,1628);
$if_exists = false;

foreach( WC()->cart->cart_contents as $key => $values )
if( in_array( $values[ ‘data’ ]->get_shipping_class_id(), $shipping_classes ) )
$if_exists = true;

if( $if_exists ) unset( $rates[‘flat_rate:13’] );

return $rates;
}

You been so helpful in the past and I’d really appreciate if any of you could give me a clue about how to list the other methods within this snippet. I’m hoping that this is a simple case of listing the methods using the appropriate coding protocol.

Thanks in advance!
Tim

  • The forum ‘Virtue Theme’ is closed to new topics and replies.