Skip to content

Commit

Permalink
Bug fix:
Browse files Browse the repository at this point in the history
Virtual product has no Shipping address
  • Loading branch information
wajihkm committed Apr 30, 2020
1 parent c54df12 commit 1d3eb87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
8 changes: 8 additions & 0 deletions includes/paytabs_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,14 @@ public static function countryGetiso3($iso_2)

return $iso_3;
}

public static function getNonEmpty(...$vars)
{
foreach ($vars as $var) {
if (!empty($var)) return $var;
}
return false;
}
}


Expand Down
40 changes: 23 additions & 17 deletions includes/paytabs_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ private function prepareOrder($order)
$stateShipping = $order->get_shipping_city();
}

$addressBilling = trim($order->get_billing_address_1() . ' ' . $order->get_billing_address_2());
$addressShipping = trim($order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2());

$lang_code = get_locale();
$lang = ($lang_code == 'ar' || substr($lang_code, 0, 3) == 'ar_') ? 'Arabic' : 'English';

Expand All @@ -342,15 +345,15 @@ private function prepareOrder($order)
'state' => $stateBilling,
'city' => $order->get_billing_city(),
'postal_code' => $postalCodeBilling,
'billing_address' => $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(),
'billing_address' => $addressBilling,

'shipping_firstname' => $order->get_shipping_first_name(),
'shipping_lastname' => $order->get_shipping_last_name(),
'country_shipping' => $countryShipping,
'state_shipping' => $stateShipping,
'city_shipping' => $order->get_shipping_city(),
'postal_code_shipping' => $postalCodeShipping,
'address_shipping' => $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2(),
'shipping_firstname' => PaytabsHelper::getNonEmpty($order->get_shipping_first_name(), $order->get_billing_first_name()),
'shipping_lastname' => PaytabsHelper::getNonEmpty($order->get_billing_last_name(), $order->get_shipping_last_name()),
'country_shipping' => PaytabsHelper::getNonEmpty($countryShipping, $countryBilling),
'state_shipping' => PaytabsHelper::getNonEmpty($stateShipping, $stateBilling),
'city_shipping' => PaytabsHelper::getNonEmpty($order->get_shipping_city(), $order->get_billing_city()),
'postal_code_shipping' => ($postalCodeShipping == '11111') ? $postalCodeBilling : $postalCodeShipping,
'address_shipping' => PaytabsHelper::getNonEmpty($addressShipping, $addressBilling),

'reference_no' => $order->get_id(),
'cms_with_version' => "WooCommerce {$woocommerce->version}",
Expand Down Expand Up @@ -428,6 +431,9 @@ private function prepareOrder2($order)
$stateShipping = $order->shipping_city;
}

$addressBilling = trim($order->billing_address_1 . ' ' . $order->billing_address_2);
$addressShipping = trim($order->shipping_address_1 . ' ' . $order->shipping_address_2);

$lang_code = get_locale();
$lang = ($lang_code == 'ar' || substr($lang_code, 0, 3) == 'ar_') ? 'Arabic' : 'English';

Expand All @@ -451,15 +457,15 @@ private function prepareOrder2($order)
'state' => $stateBilling,
'city' => $order->billing_city,
'postal_code' => $postalCodeBilling,
'billing_address' => $order->billing_address_1 . ' ' . $order->billing_address_2,

'shipping_firstname' => $order->shipping_first_name,
'shipping_lastname' => $order->shipping_last_name,
'country_shipping' => $countryShipping,
'state_shipping' => $stateShipping,
'city_shipping' => $order->shipping_city,
'postal_code_shipping' => $postalCodeShipping,
'address_shipping' => $order->shipping_address_1 . ' ' . $order->shipping_address_2,
'billing_address' => $addressBilling,

'shipping_firstname' => PaytabsHelper::getNonEmpty($order->shipping_first_name, $order->billing_first_name),
'shipping_lastname' => PaytabsHelper::getNonEmpty($order->shipping_last_name, $order->billing_last_name),
'country_shipping' => PaytabsHelper::getNonEmpty($countryShipping, $countryBilling),
'state_shipping' => PaytabsHelper::getNonEmpty($stateShipping, $stateBilling),
'city_shipping' => PaytabsHelper::getNonEmpty($order->shipping_city, $order->billing_city),
'postal_code_shipping' => ($postalCodeShipping == '11111') ? $postalCodeBilling : $postalCodeShipping,
'address_shipping' => PaytabsHelper::getNonEmpty($addressShipping, $addressBilling),

'reference_no' => $order->id,
'cms_with_version' => "WooCommerce {$woocommerce->version}",
Expand Down
4 changes: 2 additions & 2 deletions paytabs-paypage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: PayTabs - WooCommerce Payment Gateway
* Plugin URI: https://paytabs.com/
* Description: PayTabs is a <strong>3rd party payment gateway</strong>. Ideal payment solutions for your internet business.
* Version: 3.1.4
* Version: 3.1.5
* Author: PayTabs
* Author URI: https://paytabs.com/
* Revision Date : 19/April/2020
Expand All @@ -21,7 +21,7 @@
//load plugin function when woocommerce loaded
add_action('plugins_loaded', 'woocommerce_paytabs_init', 0);

define('PAYTABS_PAYPAGE_VERSION', '3.1.4');
define('PAYTABS_PAYPAGE_VERSION', '3.1.5');
define('PAYTABS_PAYPAGE_DIR', plugin_dir_path(__FILE__));
define('PAYTABS_PAYPAGE_ICONS_URL', plugins_url("icons/", __FILE__));
$PAYTABS_PAYPAGE_METHODS = [
Expand Down

0 comments on commit 1d3eb87

Please sign in to comment.