• Resolved lyonbeton

    (@lyonbeton)


    Hello,
    I want to hide a shipping method create with your plugin for a specific user only.
    Where can I find the shipping method ID ?

    add_filter( 'woocommerce_package_rates', 'hide_shipping_for_x', 10, 2 );
    function hide_shipping_for_x( $rates, $package ) {
        // client email to be excluded
        $excluded_email = "[email protected]";
     
        // Shipping rate to be excluded
        $shipping_id = 'flexible_shipping_18_shipping'; // I need to find this value !?
     
        // Get current user's email
        $user = wp_get_current_user();
        if ( empty( $user ) ) return false;
     
        if( in_array( $excluded_email, (array) $user->email ) && isset( $rates[ $shipping_id ] ) )
            unset( $rates[ $shipping_id ] );
     
        return $rates;
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author grola

    (@grola)

    This is what you need ?? https://wpde.sk/gr/r14np.png

    Thread Starter lyonbeton

    (@lyonbeton)

    Hi grola,
    Thank you for your answer.
    I’ve tried it but it didn’t work yet.
    I tried a very simplified code without any visible results.
    This should work, no ?

    add_filter( 'woocommerce_package_rates', 'hide_shipping_for_xxx', 10, 2 );
    function hide_shipping_for_xxx( $rates, $package ) {
        unset( $rates[ 'flexible_shipping_18_1' ] );
        return $rates;
    }

    It’s driving me crazy…

    Plugin Author grola

    (@grola)

    When you testing, refreshing checkout page is not enought. Try change some address fields, ie. city.

    Thread Starter lyonbeton

    (@lyonbeton)

    in fact, with the code that I’ve send to you, if I make a change in the address fields, the spinner icon above the shipping method area keeps rolling without any update.

    Thread Starter lyonbeton

    (@lyonbeton)

    It’s strange because when I look the url of te edit page for this method I see this :
    …/wp-admin/admin.php?page=wc-settings&tab=shipping&instance_id=18&action=edit&method_id=1

    But on the front side i see in the html code :
    <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flexible_shipping_18_shipping" value="flexible_shipping_18_shipping" class="shipping_method">
    The method’s ID seems to be 0, not 1.

    Plugin Author grola

    (@grola)

    Check value of radio button on checkout page: https://wpde.sk/gr/kmmc0.png

    You code works for me ??

    Thread Starter lyonbeton

    (@lyonbeton)

    value=”flexible_shipping_18_shipping”
    There is only one figure : 18

    Plugin Author grola

    (@grola)

    Maybe some other plugin modifies this value. Try use it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to target a specific shipping method’ is closed to new replies.