• Resolved Mutart

    (@mutart)


    Hi,

    is it possibile to make visible the choice of the shipping by product?

    For example:
    i have the products #1, #2, #3 and two shipping method (Free and 5€)
    When i buy the product #1 i see only one choice of shipping that is 5€.
    When i buy the product #1 or #2 or #3 (all products..) i see both choices of shipping that are Free and 5€.

    How can i make it possible?

    I created a shipping class for product #1. Products #2 and #3 haven’t a shipping class and i would that when i buy products #2 or/and #3 i see both choice shipping

    Thanks a lot

    https://www.ads-software.com/plugins/woocommerce/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    I don’t quite follow.

    Do you mean showing a shipping option per product?

    Or do you mean showing multiple options to choose from for the cart as a whole?

    Thread Starter Mutart

    (@mutart)

    Hi,

    the first: showing a shipping option per product

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Actually re-reading I think you need 2.

    Flat Rate of $5

    Free shipping enabled, but a custom function to determine if its available based on X product being in the cart only.

    Thread Starter Mutart

    (@mutart)

    I’m sorry if you don’t understand but my english is very bad….

    I have 5 products:

    Every product has one option of shipping (Ritiro in sede)

    Only 1 product has tow options of shipping (Ritiro in sede and Flat Rate of $5)

    How can i set it?

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Is Ritiro in sede different for each product.

    Thread Starter Mutart

    (@mutart)

    No, Ritiro in sede is get the product where it is made, that is that i go to the shop to get the product.

    All product has the Ritiro in sede and only 1 of these has both Ritiro in sede and Flat Rate of $5

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Ok, so use flat rate as I said for the $5.

    Then enable free shipping.

    And add some code to your theme functions.php like this:

    add_filter( 'woocommerce_shipping_free_shipping_is_available', 'custom_condtional_free_shipping' );
    
    function custom_condtional_free_shipping( $available ) {
    $cart = WC()->cart->get_cart();
    
    foreach ( $cart as $item ) {
        $_product = $item['data'];
    
        if ( $_product->id !== '100' ) {
            $available = false;
        }
    }
    
    return $available;
    }

    Replace 100 with the product ID which gets free shipping.

    Thread Starter Mutart

    (@mutart)

    No, i’m sorry that you don’t understand.

    Ritiro in sede is the first option of WooCommerce Setting on Shipping flag, between Shipping option and Unic Rate. It is’n Free Shipping. (you can see here: https://shop.birdysbakery.com/wordpress/ritiro-in-sede.png)

    So… all products have Ritiro in sede and only 1 has Ritiro in sede and Flat Rate of $5.

    I hope you understand my bad english.

    Thanks a lot for your patience.

    Thread Starter Mutart

    (@mutart)

    local_pickup!

    It’s local_pickup!

    Ritiro in sede is local_pickup

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Thats fine – the snippet above would just need:

    woocommerce_shipping_free_shipping_is_available

    Changing to:

    woocommerce_shipping_local_pickup_is_available
    Thread Starter Mutart

    (@mutart)

    I change it but nothing… it doesn’t work…

    add_filter( ‘woocommerce_shipping_local_pickup_is_available’, ‘custom_condtional_local_pickup’ );

    function custom_condtional_local_pickup( $available ) {
    $cart = WC()->cart->get_cart();

    foreach ( $cart as $item ) {
    $_product = $item[‘data’];

    if ( $_product->id !== ‘2071’ ) {
    $available = false;
    }
    }

    return $available;
    }

    Plugin Contributor Mike Jolley

    (@mikejolley)

    if ( $_product->id !== 2071 ) {

    Try that, I think the type was wrong.

    Thread Starter Mutart

    (@mutart)

    I put this code:
    add_filter( ‘woocommerce_shipping_flat_rate_is_available’, ‘custom_condtional_flat_rate’ );

    function custom_condtional_flat_rate( $available ) {
    $cart = WC()->cart->get_cart();

    foreach ( $cart as $item ) {
    $_product = $item[‘data’];

    if ( $_product->id !== 2151 ) {
    $available = false;
    }
    }

    return $available;
    }

    and it works well!

    Thanks very much! =D

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Filter shipping cost’ is closed to new replies.