Skip to content

Exclude shipping method for gallery

You may want to exclude a specific shipping method when items in the cart are from specific galleries. Replace the values for the gallery IDs you want to look for and the shipping method instance ID.

add_filter( 'sunshine_allowed_shipping_methods', 'sunshine_exclude_shipping_method', 999 );
function sunshine_exclude_shipping_method( $shipping_methods ) {

	$cart_items                      = SPC()->cart->get_cart();
	$exclude_from_gallery_ids        = array( 3048, 9485, 2284 );
	$shipping_instance_id_to_exclude = 'a3fad0ed8620ba36be97ade1d2af8358';

	if ( ! empty( $cart_items ) ) {
		foreach ( $cart_items as $item ) {
			if ( ! empty( $item['gallery_id'] ) ) {
				if ( in_array( $item['gallery_id'], $exclude_from_gallery_ids ) ) {
					unset( $shipping_methods[ $shipping_instance_id_to_exclude ] );
				}
			}
		}
	}

	return $shipping_methods;
}

Learn how to add this custom code to your WordPress website

You can learn how to find the Gallery ID here.

To find the Shipping Instance ID, go to Sunshine > Settings > Delivery & Shipping > Edit your shipping method to find the Instance ID.

Screenshot showing where to find the shipping method instance ID

Still need help?

If you have not yet found your answer in the documentation articles, please contact support

Sunshine Photo Cart for WordPress