Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Last active April 30, 2019 19:40
Show Gist options
  • Select an option

  • Save ChromeOrange/6063973 to your computer and use it in GitHub Desktop.

Select an option

Save ChromeOrange/6063973 to your computer and use it in GitHub Desktop.

Revisions

  1. ChromeOrange revised this gist Sep 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Hide ALL shipping options when free shipping is available
    add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 );
    add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 1 );

    /**
    * Hide ALL Shipping option when free shipping is available
  2. ChromeOrange revised this gist Oct 23, 2013. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -10,18 +10,18 @@ function hide_all_shipping_when_free_is_available( $available_methods ) {

    if( isset( $available_methods['free_shipping'] ) ) :

    // Get Free Shipping array into a new array
    $freeshipping = array();
    $freeshipping = $available_methods['free_shipping'];
    foreach ( $available_methods as $available_method ) {

    // Empty the $available_methods array
    unset( $available_methods );
    $available_method = get_object_vars( $available_method );

    // Add Free Shipping back into $avaialble_methods
    $available_methods = array();
    $available_methods[] = $freeshipping;
    if ( $available_method['id'] != 'free_shipping' ) :

    endif;
    unset( $available_methods[$available_method['id']] );

    endif;
    }

    endif;

    return $available_methods;
    }
  3. ChromeOrange revised this gist Jul 23, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    // Hide ALL shipping options when free shipping is available
    add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
    add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 );

    /**
    * Hide ALL Shipping option when free shipping is available
    @@ -8,7 +8,7 @@
    */
    function hide_all_shipping_when_free_is_available( $available_methods ) {

    if( isset( $available_methods['free_shipping'] ) ) :
    if( isset( $available_methods['free_shipping'] ) ) :

    // Get Free Shipping array into a new array
    $freeshipping = array();
  4. ChromeOrange created this gist Jul 23, 2013.
    27 changes: 27 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // Hide ALL shipping options when free shipping is available
    add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );

    /**
    * Hide ALL Shipping option when free shipping is available
    *
    * @param array $available_methods
    */
    function hide_all_shipping_when_free_is_available( $available_methods ) {

    if( isset( $available_methods['free_shipping'] ) ) :

    // Get Free Shipping array into a new array
    $freeshipping = array();
    $freeshipping = $available_methods['free_shipping'];

    // Empty the $available_methods array
    unset( $available_methods );

    // Add Free Shipping back into $avaialble_methods
    $available_methods = array();
    $available_methods[] = $freeshipping;

    endif;

    return $available_methods;
    }