Last active
October 29, 2019 19:11
-
-
Save BFTrick/d4a21524a8f7b25ec296 to your computer and use it in GitHub Desktop.
Revisions
-
BFTrick revised this gist
Sep 7, 2016 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,9 @@ * Plugin Name: WooCommerce Enable Free Shipping on a Per Product Basis * Plugin URI: https://gist.github.com/BFTrick/d4a21524a8f7b25ec296 * Description: Enable free shipping for certain products * Author: Patrick Rauland & eugenf * Author URI: http://speakinginbytes.com/ * Version: 1.0.2 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,13 +60,13 @@ public function patricks_enable_free_shipping( $is_available ) { // loop through the items checking to make sure they all have the right class foreach ( $cart_items as $key => $item ) { if ( ! in_array( $item['data']->get_shipping_class(), $eligible ) ) { // this item doesn't have the right class. return default availability return $is_available; } } // nothing out of the ordinary return true return true; } -
BFTrick revised this gist
May 10, 2015 . 1 changed file with 38 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ * Description: Enable free shipping for certain products * Author: Patrick Rauland * Author URI: http://speakinginbytes.com/ * Version: 1.0.1 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,29 +27,29 @@ class WC_Enable_Free_Shipping { protected static $instance = null; /** * Initialize the plugin. * * @since 1.0 */ private function __construct() { // add our check add_filter( 'woocommerce_shipping_free_shipping_is_available', array( $this, 'patricks_enable_free_shipping' ), 20 ); } /** * Enable free shipping for orders with products that have the free-shipping shipping class slug * * @param bool $is_available * @return bool * @since 1.0 */ public function patricks_enable_free_shipping( $is_available ) { global $woocommerce; // set the shipping classes that are eligible $eligible = array( 'free-shipping' ); @@ -59,35 +59,35 @@ public function patricks_enable_free_shipping( $is_available ) { // loop through the items checking to make sure they all have the right class foreach ( $cart_items as $key => $item ) { if ( ! in_array( $item['data']->get_shipping_class(), $eligible ) ) { // this item doesn't have the right class. return false return false; } } // nothing out of the ordinary return the default value return $is_available; } /** * Return an instance of this class. * * @return object A single instance of this class. * @since 1.0 */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } } add_action( 'init', array( 'WC_Enable_Free_Shipping', 'get_instance' ), 0 ); endif; -
BFTrick revised this gist
Dec 10, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <?php /** * Plugin Name: WooCommerce Enable Free Shipping on a Per Product Basis * Plugin URI: https://gist.github.com/BFTrick/d4a21524a8f7b25ec296 * Description: Enable free shipping for certain products * Author: Patrick Rauland * Author URI: http://speakinginbytes.com/ @@ -36,7 +36,7 @@ class WC_Enable_Free_Shipping { */ private function __construct() { // add our check add_filter( 'woocommerce_shipping_free_shipping_is_available', array( $this, 'patricks_enable_free_shipping' ), 20 ); } @@ -47,7 +47,7 @@ private function __construct() { * @return bool * @since 1.0 */ public function patricks_enable_free_shipping( $is_available ) { global $woocommerce; @@ -88,6 +88,6 @@ public static function get_instance() { } add_action( 'init', array( 'WC_Enable_Free_Shipping', 'get_instance' ), 0 ); endif; -
BFTrick created this gist
Dec 10, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ <?php /** * Plugin Name: WooCommerce Enable Free Shipping on a Per Product Basis * Plugin URI: https://gist.github.com/BFTrick/______________ * Description: Enable free shipping for certain products * Author: Patrick Rauland * Author URI: http://speakinginbytes.com/ * Version: 1.0 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ if ( ! class_exists( 'WC_Enable_Free_Shipping' ) ) : class WC_Enable_Free_Shipping { protected static $instance = null; /** * Initialize the plugin. * * @since 1.0 */ private function __construct() { // add our check add_filter( 'woocommerce_shipping_free_shipping_is_available', array( $this, 'patricks_enable_free_shipping' ) ); } /** * Enable free shipping for orders with products that have the free-shipping shipping class slug * * @param bool $is_available * @return bool * @since 1.0 */ public function patricks_enable_free_shipping( is_available ) { global $woocommerce; // set the shipping classes that are eligible $eligible = array( 'free-shipping' ); // get cart contents $cart_items = $woocommerce->cart->get_cart(); // loop through the items checking to make sure they all have the right class foreach ( $cart_items as $key => $item ) { if ( ! in_array( $item['data']->shipping_class, $eligible ) ) { // this item doesn't have the right class. return false return false; } } // nothing out of the ordinary return the default value return $is_available; } /** * Return an instance of this class. * * @return object A single instance of this class. * @since 1.0 */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } } add_action( 'admin_init', array( 'WC_Enable_Free_Shipping', 'get_instance' ), 0 ); endif;