0

Use Case: Multiple Shipping Methods per Order

Context

We have a WooCommerce online store with 2 products:

  1. Framing Product. Price: 50 USD.

  2. Print Product. Price: 20 USD.

Plugins installed:

  • FedEx WooCommerce Shipping with Print Label

  • ...

Shipping Rates:

  • For Framing Products we need to apply a Flat Shipping Rate [ 15 USD ] since we deliver these products personally.

  • For Print Products we need to use Fedex delivery service.

Goal

We need to allow our customers to have in the same order both kind of products: { Framing Products, Print Products }.

Cart Example

enter image description here

Total: 160 + 30 + [Fedex Quote] USD = 190 + [Fedex Quote] USD

Question

Is there anyway to accomplish this?

After installed the plugin: FedEx WooCommerce Shipping with Print Label we didn't find any option for this use case.

1 Answer 1

0

This case is possible with FedEx WooCommerce Shipping with Print Label. All you need is the following free add-ons and the code below.

  • Hide WooCommerce Shipping Methods based on Shipping Class and Zones
  • Skip Shipping calculation based on WooCommerce Shipping Class

These free plugins as well as, a similar case is already explained very well in the following documentation- WooCommerce Shipping – FedEx Live Rate Adjustment based on Shipping Classes.

Here is the code that you need to add to your functions.php file...

/**
 * Snippet to Add an Additional Cost to the Shipping Service based on Shipping Class
 * Created on 28 March 2019
 * PluginHive Plugins: https://www.pluginhive.com/plugins/
**/

add_filter( 'woocommerce_package_rates', 'adjustment_in_rates_of_product_with_shipping_class', 12, 2 );

function adjustment_in_rates_of_product_with_shipping_class( $available_shipping_methods, $package ) {

   // Shipping class slug that need to add extra cost
    $shipping_class = array(
        'other',
    );

   // Give here Extra Cost you want add
    $extra_cost = 100;

    // Enter the Shipping Method Value
    $shipping_services = array(
       'wf_shipping_ups:01',
       'wf_shipping_ups:02',
       'wf_shipping_ups:03',
       'wf_shipping_ups:07',
       'wf_shipping_ups:08',
       'wf_shipping_ups:11',
       'wf_shipping_ups:12',
       'wf_shipping_ups:13',
       'wf_shipping_ups:14',
       'wf_shipping_ups:59',
       'wf_shipping_ups:54',
       'wf_shipping_ups:65',
       'wf_shipping_ups:92',
       'wf_shipping_ups:93',
       'wf_shipping_ups:94',
    );

    $shipping_class_exists = false;
    foreach(WC()->cart->get_cart_contents() as $key => $values) {
        if ( in_array($values['data']->get_shipping_class() , $shipping_class) ) {
            $shipping_class_exists = true;
            break;
        }
    }

    if ($shipping_class_exists) {
        foreach ($available_shipping_methods as $key => $value) {
            if ( in_array($value->get_id() , $shipping_services) ) {
                $available_shipping_methods[$key]->cost += $extra_cost;
            }
        }
    }

    return $available_shipping_methods;
}

If you have any more query you can leave a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.