Skip to content

Commit

Permalink
Merge pull request #287 from woocommerce/fix/issue-286
Browse files Browse the repository at this point in the history
Fix noshipping by still checking shipping on products
  • Loading branch information
bor0 authored Jun 28, 2017
2 parents cd23981 + 537c37a commit a7df823
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions includes/class-wc-gateway-ppec-checkout-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ public function paypal_shipping_details() {
return;
}

if ( ! WC_Gateway_PPEC_Plugin::needs_shipping() ) {
return;
}

?>
<h3><?php _e( 'Shipping details', 'woocommerce-gateway-paypal-express-checkout' ); ?></h3>
<?php
Expand Down
6 changes: 3 additions & 3 deletions includes/class-wc-gateway-ppec-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function get_set_express_checkout_params( array $args ) {
'PAYMENTREQUEST_0_SHIPPINGAMT' => $details['shipping'],
'PAYMENTREQUEST_0_TAXAMT' => $details['order_tax'],
'PAYMENTREQUEST_0_SHIPDISCAMT' => $details['ship_discount_amount'],
'NOSHIPPING' => 0,
'NOSHIPPING' => WC_Gateway_PPEC_Plugin::needs_shipping() ? 0 : 1,
)
);

Expand Down Expand Up @@ -840,10 +840,10 @@ public function get_do_express_checkout_params( array $args ) {
'order_id' => $order_id,
'order_key' => $order_key,
) ),
'NOSHIPPING' => 0,
'NOSHIPPING' => WC_Gateway_PPEC_Plugin::needs_shipping() ? 0 : 1,
);

if ( ! empty( $details['shipping_address'] ) ) {
if ( WC_Gateway_PPEC_Plugin::needs_shipping() && ! empty( $details['shipping_address'] ) ) {
$params = array_merge(
$params,
$details['shipping_address']->getAddressParams( 'PAYMENTREQUEST_0_SHIPTO' )
Expand Down
18 changes: 18 additions & 0 deletions includes/class-wc-gateway-ppec-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,22 @@ public function plugin_action_links( $links ) {

return array_merge( $plugin_links, $links );
}

/**
* Check if shipping is needed for PayPal.
*
* @since 1.4.1
* @version 1.4.1
*
* @return bool
*/
public static function needs_shipping() {
// In case there are no shipping methods defined, we still return true (see #249)
if ( ! wc_shipping_enabled() || 0 === wc_get_shipping_method_count( true ) ) {
return true;
}

// Otherwise go through all items and see if they require shipping (e.g. virtual items will not, see #286)
return WC()->cart->needs_shipping();
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ https://gist.github.com/mikejolley/ad2ecc286c9ad6cefbb7065ba6dfef48

= 1.4.1 =
* Fix - Properly calculate whether Billing phone is required or not.
* Fix - Set NOSHIPPING based on product shipping requiredness (e.g. virtual products do not need shipping, etc)

= 1.4.0 =
* Tweak - Use shipping discount instead of tax when adjustment negative.
Expand Down

0 comments on commit a7df823

Please sign in to comment.