[Resolved] Hide shipping method for WOOCOMMERCE

Home Forums Support Hide shipping method for WOOCOMMERCE

  • This topic has 3 replies, 2 voices, and was last updated 5 months ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1242611
    David

    Hello, this is Dave!

    I’m using woocommerce and i wat to make something with the free shipping methods, because woocmmerce shows the “free shipping” and the “standar shipping” when a minimum quantity is reached in a purchase.

    What I want is for the “standard shipping” to disappear when that happens and woocommerce docs that is possible whith a code that you must to add in the functions.php. I haven’t a child theme and don’t want to use if i can use an “element hook”

    This is the documentation:
    https://docs.woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/#

    And this is the woocommerce code. Can i use this code with a element hook?

    /**
    * Hide shipping rates when free shipping is available.
    * Updated to support WooCommerce 2.6 Shipping Zones.
    *
    * @param array $rates Array of rates found for the package.
    * @return array
    */
    function my_hide_shipping_when_free_is_available( $rates ) {
    $free = array();
    foreach ( $rates as $rate_id => $rate ) {
    if ( ‘free_shipping’ === $rate->method_id ) {
    $free[ $rate_id ] = $rate;
    break;
    }
    }
    return ! empty( $free ) ? $free : $rates;
    }
    add_filter( ‘woocommerce_package_rates’, ‘my_hide_shipping_when_free_is_available’, 100 );

    #1242700
    David
    Staff
    Customer Support

    Hi there,

    unfortunately you cannot use Hooks to add that particular code.
    You can add it using the Code Snippets plugin

    #1242730
    David

    Thanks a lot for your quick reply. Maybe i’m going to use this plugin.

    Thank you so much

    #1242824
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.