From a0be65596f8dd88e5861e4ef340a97e242a901db Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 13 Aug 2015 23:54:16 +0100 Subject: [PATCH] COD: remove shipping check if the cart is 100% virtual. @claudiosmweb --- .../gateways/cod/class-wc-gateway-cod.php | 53 +++++++++---------- readme.txt | 1 + 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/includes/gateways/cod/class-wc-gateway-cod.php b/includes/gateways/cod/class-wc-gateway-cod.php index 5ce91f96456..e15c4c3cfcf 100644 --- a/includes/gateways/cod/class-wc-gateway-cod.php +++ b/includes/gateways/cod/class-wc-gateway-cod.php @@ -113,42 +113,39 @@ class WC_Gateway_COD extends WC_Payment_Gateway { * @return bool */ public function is_available() { - $order = null; + $order = null; + $needs_shipping = false; - if ( ! $this->enable_for_virtual ) { - if ( WC()->cart && ! WC()->cart->needs_shipping() ) { - return false; - } + // Test if shipping is needed first + if ( WC()->cart && WC()->cart->needs_shipping() ) { + $needs_shipping = true; + } elseif ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) { + $order_id = absint( get_query_var( 'order-pay' ) ); + $order = wc_get_order( $order_id ); - if ( is_page( wc_get_page_id( 'checkout' ) ) && 0 < get_query_var( 'order-pay' ) ) { - $order_id = absint( get_query_var( 'order-pay' ) ); - $order = wc_get_order( $order_id ); - - // Test if order needs shipping. - $needs_shipping = false; - - if ( 0 < sizeof( $order->get_items() ) ) { - foreach ( $order->get_items() as $item ) { - $_product = $order->get_product_from_item( $item ); - - if ( $_product->needs_shipping() ) { - $needs_shipping = true; - break; - } + // Test if order needs shipping. + if ( 0 < sizeof( $order->get_items() ) ) { + foreach ( $order->get_items() as $item ) { + $_product = $order->get_product_from_item( $item ); + if ( $_product->needs_shipping() ) { + $needs_shipping = true; + break; } } - - $needs_shipping = apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); - - if ( $needs_shipping ) { - return false; - } } } - if ( ! empty( $this->enable_for_methods ) ) { + $needs_shipping = apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping ); - // Only apply if all packages are being shipped via local pickup + // Virtual order, with virtual disabled + if ( ! $this->enable_for_virtual && ! $needs_shipping ) { + return false; + } + + // Check methods + if ( ! empty( $this->enable_for_methods ) && $needs_shipping ) { + + // Only apply if all packages are being shipped via chosen methods, or order is virtual $chosen_shipping_methods_session = WC()->session->get( 'chosen_shipping_methods' ); if ( isset( $chosen_shipping_methods_session ) ) { diff --git a/readme.txt b/readme.txt index 3a951739f2f..2cb64e0c42b 100644 --- a/readme.txt +++ b/readme.txt @@ -161,6 +161,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Fix - Ajax variation handling when 'any' attribute is set. * Fix - Run html_entity_decode over text attributes to fix problems with quote characters. +* Fix - COD: remove shipping check if the cart is 100% virtual. * Tweak - Order variations by menu_order by fallback to ID. * Tweak - Include attribute archives support in the breadcrumbs. * Tweak - woocommerce_variable_children_args hook.