• Resolved bitfenix

    (@bitfenix)


    Hello people,

    I have one product with a few variants. When product variant is added to the cart, Bring shipping options and prices are:
    P? D?ren: 120kr
    Kliman?ytral Servicepakke: 70kr

    But when one specific variant is added to the cart I need changing this shipping option prices to:
    P? D?ren: 0kr
    Kliman?ytral Servicepakke: 0kr

    Is this possible to make with some condition that will match that specific product variant, with Bring plugin?

    Thanks in advance,
    Bit

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eivin Landa

    (@forsvunnet)

    Hi,

    It’s possible, but it requires some custom code. You can use bring_shipping_rates filter implement custom logic. Here’s some example code that might be helpful. This removes any bring rates if any of the products in the cart has any of the specified shipping classes. You could modify this to set the rate price to 0.

    
    <?php
    /**
     * Filter the bring shipping rates.
     */
    add_filter('bring_shipping_rates', function( $rates ) {
    	$shipping_classes = [
    		'heavy',
    		'pallet',
    	];
    	// Look for items with a shipping class that doesn not allow mail.
    	$items = WC()->cart->get_cart();
    	foreach ( $items as $item ) {
    		$shipping_class = $item['data']->get_shipping_class();
    		if ( in_array( $shipping_class, $shipping_classes ) ) {
    			return [];
    		}
    	}
    	return $rates;
    }, 999 );
    
    • This reply was modified 5 years, 3 months ago by Eivin Landa.
    Thread Starter bitfenix

    (@bitfenix)

    I knew I should be a backend dev : ) Thank you for providing example code, will place it in child theme function file and then try to modify it.

    Thread Starter bitfenix

    (@bitfenix)

    Forgot to write so we can mark the topic as solved :>

    If someone need the same thing, the solution was:

    add_filter('bring_shipping_rates', function( $rates ) {
    	$shipping_classes = [
    		'freeshipping',
    	];
    
        $free = false;
    	$items = WC()->cart->get_cart();
    	foreach ( $items as $item ) {
    		$shipping_class = $item['data']->get_shipping_class();
    		if ( in_array( $shipping_class, $shipping_classes ) ) {
    			$free = true;
    		}
    	}
    
        if ($free) {
            $rates[0]['cost'] = 0;
        }
    	return $rates;
    }, 999 );

    This code is placed in theme’s function.php file. Before this, shipping class needs to be created (name of the shipping class will be matched here https://prntscr.com/qgv9wf)

    After that these lines are commented https://prntscr.com/qgvd6w in the wp-cart-functions.php in the woocommerce plugin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change shipping prices for specific product variant’ is closed to new replies.