diff --git a/.gitignore b/.gitignore
index 1660023..5c24593 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,7 @@ Thumbs.db
# Temporary folders
/_temp
+
+# PHPStorm
+
+/.idea
\ No newline at end of file
diff --git a/assets/provinces.css b/assets/provinces.css
new file mode 100644
index 0000000..4c8a0de
--- /dev/null
+++ b/assets/provinces.css
@@ -0,0 +1,48 @@
+.woocommerce-billing-fields__field-wrapper.active {
+ display: flex;
+ flex-wrap: wrap;
+}
+
+#billing_first_name_field {
+ order: 1;
+}
+
+#billing_last_name_field {
+ order: 2;
+}
+
+#billing_company_field {
+ order: 3;
+}
+
+#billing_country_field {
+ order: 4;
+}
+
+#billing_state_field {
+ order: 5;
+}
+
+#billing_city_field {
+ order: 6;
+}
+
+#billing_address_1_field {
+ order: 7;
+}
+
+#billing_address_2_field {
+ order: 8;
+}
+
+#billing_postcode_field {
+ order: 9;
+}
+
+#billing_phone_field {
+ order: 10;
+}
+
+#billing_email_field {
+ order: 11;
+}
\ No newline at end of file
diff --git a/assets/provinces.js b/assets/provinces.js
new file mode 100644
index 0000000..27dc594
--- /dev/null
+++ b/assets/provinces.js
@@ -0,0 +1,14 @@
+(function($) {
+ $('#billing_country_field').on('change', function() {
+
+ // Get country code
+ var country_code = $(this).find('#billing_country').val();
+
+ // Match country code with Vietnam
+ if(country_code == 'VN') {
+ $('.woocommerce-billing-fields__field-wrapper').addClass('active');
+ } else {
+ $('.woocommerce-billing-fields__field-wrapper').removeClass('active');
+ }
+ })
+})(jQuery)
\ No newline at end of file
diff --git a/inc/class-wooviet-admin-page.php b/inc/class-wooviet-admin-page.php
index 4f10bc4..08c33e4 100644
--- a/inc/class-wooviet-admin-page.php
+++ b/inc/class-wooviet-admin-page.php
@@ -239,6 +239,42 @@ class WooViet_Admin_Page {
+
+
the PayPal Express Checkout gateway', 'woo-viet' ), 'https://docs.woocommerce.com/document/paypal-express-checkout/' ) ?>
+
+
+ >
+
+
+
+
+
diff --git a/inc/class-wooviet-notices.php b/inc/class-wooviet-notices.php
index ebb0588..25e339f 100644
--- a/inc/class-wooviet-notices.php
+++ b/inc/class-wooviet-notices.php
@@ -86,7 +86,7 @@ class WooViet_Notices {
$line1 = __( 'Please help us to improve Woo Viet.', 'woo-viet' );
$line2 = __( 'Rate us!', 'woo-viet' );
- $line3 = __( 'Or run a short survery:', 'woo-viet' );
+ $line3 = __( 'Or run a short survey:', 'woo-viet' );
$line4 = 'tiếng Việt - English';
$line5 = __( 'Dismiss this notice', 'woo-viet' );
$link = admin_url( 'admin.php?page=woo-viet&wooviet_dismiss=displaying_survey_after_4_weeks' );
@@ -104,4 +104,4 @@ class WooViet_Notices {
', $line1, $line2, $line3, $line4, $line5, $link );
}
-}
\ No newline at end of file
+}
diff --git a/inc/class-wooviet-onepay-domestic.php b/inc/class-wooviet-onepay-domestic.php
index ad39401..e763c66 100644
--- a/inc/class-wooviet-onepay-domestic.php
+++ b/inc/class-wooviet-onepay-domestic.php
@@ -255,22 +255,54 @@ class WooViet_OnePay_Domestic extends WC_Payment_Gateway {
);
$order->add_order_note( $order_note );
- // If the payment is successful, update the order
- if ( "0" == $vpc_TxnResponseCode ) {
- $order->payment_complete();
+
+ // Do action for the order based on the response code from OnePay
+ // This is an intentional DRY switch - refer to #DRY_vpc_TxnResponseCode below
+ switch ( $vpc_TxnResponseCode ) {
+ case '0':
+ // If the payment is successful, update the order
+ $order->payment_complete();
+ break;
+ case '99':
+ // If the user cancels payment, cancel the order
+ $order->cancel_order();
+ break;
+ default:
+ // For other cases, do nothing. By default, the order status is still "Pending Payment"
+ break;
}
+
// Log data
$message_log = sprintf('process_onepay_response_data - Order ID: %1$s - Order Note: %2$s - http_args: %3$s', $order_id, $order_note, print_r($args, true) );
self::log( $message_log);
-
- // Return the info
+
+ // Do the last actions based on $type
switch ( $type ) {
- case 'return':
- wp_redirect( $this->get_return_url( $order ) );
+ case 'return': // Add info from OnePay and redirect to the appropriate URLs
+
+ wc_add_notice( __( 'OnePay info: ', 'woo-viet') . $this->OnePay_getResponseDescription( $vpc_TxnResponseCode ), 'notice' );
+
+ // This is an intentional DRY switch - refer to #DRY_vpc_TxnResponseCode above
+ // I need to make sure that `ipn` case below and message_log can be executed as well.
+ switch ( $vpc_TxnResponseCode ) {
+ case '0':
+ // If the payment is successful, redirect to the order page
+ wp_redirect( $this->get_return_url( $order ) );
+ break;
+ case '99':
+ // If the user cancels payment, redirect to the canceled cart page
+ wp_redirect( $order->get_cancel_order_url_raw() );
+ break;
+ default:
+ // For other cases, redirect to the payment page
+ wp_redirect( $order->get_checkout_payment_url () );
+ break;
+ }
+
break;
- case 'ipn':
+ case 'ipn': // Output the data to the page content
exit( 'responsecode=1&desc=confirm-success' );
break;
diff --git a/inc/class-wooviet-provinces.php b/inc/class-wooviet-provinces.php
index 6251375..c7f9b95 100644
--- a/inc/class-wooviet-provinces.php
+++ b/inc/class-wooviet-provinces.php
@@ -6,8 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* The class to handle Vietnam Provinces
*
- * @todo Arrange the orders of fields displaying in the checkout page: Country - Province - District - Address
- *
* @author htdat
* @since 1.0
*
@@ -21,6 +19,9 @@ class WooViet_Provinces {
add_filter( 'woocommerce_states', array( $this, 'add_provinces' ) );
add_filter( 'woocommerce_get_country_locale', array( $this, 'edit_vn_locale' ) );
add_filter( 'woocommerce_localisation_address_formats', array( $this, 'edit_vn_address_formats' ) );
+
+ // Enqueue province scripts
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_provinces_scripts' ) );
}
/**
@@ -136,4 +137,19 @@ class WooViet_Provinces {
return $states;
}
-}
\ No newline at end of file
+
+ /**
+ * Enqueue provinces scripts
+ *
+ * Arrange the address field orders to the Vietnam standard in the checkout page: Country - Province - District - Address
+ * @author Longkt
+ * @since 1.4
+ */
+ public function load_provinces_scripts() {
+ // Enqueue province style
+ wp_enqueue_style( 'woo-viet-provinces-style', WOO_VIET_URL . 'assets/provinces.css' );
+
+ // Enqueue province script
+ wp_enqueue_script( 'woo-viet-provinces-script', WOO_VIET_URL . 'assets/provinces.js', array( 'jquery' ), '1.0', true );
+ }
+}
diff --git a/inc/class-wooviet-vnd-paypal-express-checkout.php b/inc/class-wooviet-vnd-paypal-express-checkout.php
new file mode 100644
index 0000000..435afb0
--- /dev/null
+++ b/inc/class-wooviet-vnd-paypal-express-checkout.php
@@ -0,0 +1,180 @@
+ppec_exchange_rate = (int) $ppec_exchange_rate;
+ $this->ppec_currency = $ppec_currency;
+
+ $this->ppec_description = sprintf( __( 'The prices will be converted to %1$s in the PayPal Express Checkout pages with the exchange rate %2$s.', 'woo-viet' ),
+ " $this->ppec_currency",
+ " $this->ppec_currency / VND = $this->ppec_exchange_rate"
+ );
+
+ // Match response currency of PayPal with local order
+ add_action( 'woocommerce_paypal_express_checkout_valid_ipn_request', array( $this, 'ppec_match_currency_order' ) );
+
+ // Add exchange rate before send request to PayPal
+ add_filter( 'woocommerce_paypal_express_checkout_request_body', array( $this, 'ppec_convert_prices' ) );
+
+ // Load the method to add the exchange rate info for this gateway
+ $this->ppec_exchange_rate_info();
+
+ }
+
+ /**
+ * Match response currency from PayPal with the order
+ *
+ * @param $posted_data
+ */
+ public function ppec_match_currency_order( $posted_data ) {
+
+ if( $posted_data['mc_currency'] ) {
+ $posted_data['mc_currency'] = $order->get_currency();
+ }
+
+ }
+
+ /**
+ * @param $params
+ * @return mixed
+ */
+ public function ppec_convert_prices( $params ) {
+
+ if( isset( $params['PAYMENTREQUEST_0_CURRENCYCODE'] ) ) {
+
+ $params['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->ppec_currency;
+
+ if( isset( $params['PAYMENTREQUEST_0_AMT'] ) ) {
+ $params['PAYMENTREQUEST_0_AMT'] = round( $params['PAYMENTREQUEST_0_AMT'] / $this->ppec_exchange_rate, 2 );
+ }
+
+ if( isset( $params['PAYMENTREQUEST_0_ITEMAMT'] ) ) {
+ $params['PAYMENTREQUEST_0_ITEMAMT'] = round( $params['PAYMENTREQUEST_0_ITEMAMT'] / $this->ppec_exchange_rate, 2 );
+ }
+
+ if( isset( $params['PAYMENTREQUEST_0_SHIPPINGAMT'] ) ) {
+ $params['PAYMENTREQUEST_0_SHIPPINGAMT'] = round( $params['PAYMENTREQUEST_0_SHIPPINGAMT'] / $this->ppec_exchange_rate, 2 );
+ }
+
+ if( isset( $params['PAYMENTREQUEST_0_TAXAMT'] ) ) {
+ $params['PAYMENTREQUEST_0_TAXAMT'] = round( $params['PAYMENTREQUEST_0_TAXAMT'] / $this->ppec_exchange_rate, 2 );
+ }
+
+ if( isset( $params['PAYMENTREQUEST_0_SHIPDISCAMT'] ) ) {
+ $params['PAYMENTREQUEST_0_SHIPDISCAMT'] = round( $params['PAYMENTREQUEST_0_SHIPDISCAMT'] / $this->ppec_exchange_rate, 2 );
+ }
+
+ $count = 0;
+
+ while( isset( $params['L_PAYMENTREQUEST_0_AMT' . $count] ) ) {
+ $params['L_PAYMENTREQUEST_0_AMT' . $count] = round( $params['L_PAYMENTREQUEST_0_AMT' . $count] / $this->ppec_exchange_rate, 2 );
+ $count++;
+ }
+ }
+
+ return $params;
+
+ }
+
+ /**
+ * Add the exchange rate info in the suitable locations before proceeding in the PayPal pages
+ */
+ public function ppec_exchange_rate_info() {
+
+ // Check if "Checkout on cart page" is enabled.
+ if( 'yes' === wc_gateway_ppec()->settings->cart_checkout_enabled ) {
+ add_action( 'woocommerce_proceed_to_checkout', array( $this, 'add_ppec_button_exchange_rate_info' ), 30 );
+ }
+
+ // Check if "Checkout on Single Product" is enabled.
+ if( 'yes' === wc_gateway_ppec()->settings->checkout_on_single_product_enabled ) {
+ add_action( 'woocommerce_after_add_to_cart_form', array( $this, 'add_ppec_button_exchange_rate_info' ), 30 );
+ }
+
+ // Check if "Enable PayPal Credit" is enabled.
+ if( 'yes' === wc_gateway_ppec()->settings->credit_enabled ) {
+ add_filter( 'woocommerce_paypal_express_checkout_settings', array( $this, 'add_paypal_credit_exchange_rate_info' ), 11 );
+ }
+
+ // Add the exchange rate info for PPEC in Checkout page
+ add_filter( 'option_woocommerce_ppec_paypal_settings', array( $this, 'add_ppec_checkout_exchange_rate_info' ), 11 );
+
+ }
+
+ /**
+ * Display the exchange rate info of PPEC in Cart and Single Product page
+ */
+ public function add_ppec_button_exchange_rate_info() {
+
+ echo '
' . $this->ppec_description . '
';
+
+ }
+
+ /**
+ * Display the exchange rate info of PP Credit in Checkout page
+ *
+ * @param $value
+ * @return mixed
+ */
+ public function add_paypal_credit_exchange_rate_info( $value ) {
+
+ if ( ! is_admin() ) {
+ $value['description']['default'] .= ' ';
+ $value['description']['default'] .= $this->ppec_description;
+ }
+
+ return $value;
+ }
+
+ /**
+ * Display the exchange rate info of PPEC in Checkout page
+ *
+ * @param $value
+ * @return mixed
+ */
+ public function add_ppec_checkout_exchange_rate_info( $value ) {
+
+ if ( ! is_admin() ) {
+ $value['description'] .= ' ';
+ $value['description'] .= $this->ppec_description;
+ }
+ return $value;
+
+ }
+
+}
\ No newline at end of file
diff --git a/inc/class-wooviet-vnd-paypal-standard.php b/inc/class-wooviet-vnd-paypal-standard.php
index a515164..74f9861 100644
--- a/inc/class-wooviet-vnd-paypal-standard.php
+++ b/inc/class-wooviet-vnd-paypal-standard.php
@@ -43,6 +43,9 @@ class WooViet_VND_PayPal_Standard {
// Add the exchange rate info for this gateway in the checkout page before proceeding in the PayPal pages
add_filter( 'option_woocommerce_paypal_settings', array( $this, 'add_exchange_rate_info' ), 11 );
+
+ // Match currency of Paypal with local order
+ add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_currency_order' ), 10 );
}
/**
@@ -107,4 +110,18 @@ class WooViet_VND_PayPal_Standard {
return $value;
}
+ /*
+ * Match response currency from Paypal IPN with the order
+ *
+ * Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/
+ *
+ * @author Longkt
+ * @since 1.4
+ */
+ public function match_currency_order($posted) {
+ if($posted['mc_currency']) {
+ $posted['mc_currency'] = $order->get_currency();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/readme.md b/readme.md
index eb3db7a..fcb1f90 100644
--- a/readme.md
+++ b/readme.md
@@ -1,80 +1,23 @@
# Woo Viet - WooCommerce for Vietnam
-| Name | Value |
-|:---|:---|
-| Contributors | htdat |
-|Tags| WooCommerce Vietnam, vietnam, vietnamese, vietnam provinces, paypal for vietnam dong, vnd, vietnam dong, vietnam currency, vietnam customization |
-| Requires at least | 4.3 |
-| Tested up to | 4.8 |
-| Stable tag | 1.3 |
-| License | GPLv2 or later |
-| License URI | https://www.gnu.org/licenses/gpl-2.0.html |
-
-Add features to WooCommerce stores having anything related to Vietnam: currency, shipping address, PayPal and more.
-
-## Description
-
**"Woo Viet - WooCommerce for Vietnam" brings the features that help to run WooCommerce stores and customize them for Vietnam much easier.**
+See here https://wordpress.org/plugins/woo-viet/
+
Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo-viet/
-## FEATURES
-
-* Change the VND currency symbol `đ` to anything, e.g: `VND`, `VNĐ`, `đồng`, etc.
-* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. This is not available in WooCommerce by default.
-* Add districts to Vietnam provinces.
-* Convert `000` of prices to `K` (or anything). E.g: `50000` (VND) will be `50K` (VND), or `50 thousand` (VND).
-* Support `VND` for [the PayPal Standard gateway](https://docs.woocommerce.com/document/paypal-standard/). Convert `VND` prices to any PayPal supported currency before sending visitors to the PayPal pages.
-* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/).
-
-## ROAD MAP
-
-In the future, this plugin will add more and more features for the Vietnam market:
-
-* Integrate all districts to Vietnam provinces.
-* Integrate at least one solution for collecting money by phone cards.
-* Integrate the Vietnam payment gateways like 1Pay, OnePay, BaoKim, Ngan Luong, etc.
-* Integrate the Vietnam shipping solutions like ShipChung, Giaohangnhanh, ViettelPost, etc.
-
-## WHERE CAN I CONTRIBUTE MY CODE OR IDEA?
-
-* You can report bugs or contribute code on [this GitHub repo](https://github.com/htdat/woo-viet).
-* Please also do let us know if the "bug" is just a grammar/spelling error in both English and Vietnamese. We try to make our products as perfect as possible.
-
-## INSTALLATION
-
-Follow these steps to install and use the plugin:
-
-1. Upload the plugin files to the `/wp-content/plugins/woo-viet` directory, or install the plugin through the WordPress plugins screen directly.
-1. Activate the plugin through the `Plugins` screen in WordPress.
-1. Go to the `WooCommerce -> Woo Viet` screen and configure the plugin.
-
-## Installation
-
-Follow these steps to install and use the plugin:
-
-1. Upload the plugin files to the `/wp-content/plugins/woo-viet` directory, or install the plugin through the WordPress plugins screen directly.
-1. Activate the plugin through the 'Plugins' screen in WordPress.
-1. Go to the `WooCommerce -> Woo Viet` screen and configure the plugin.
-
-
-## Frequently Asked Questions
-
-### WHERE CAN I CONTRIBUTE MY CODE OR IDEA?
-
-* You can report bugs or contribute code on [this GitHub repo](https://github.com/htdat/woo-viet).
-* Please also do let us know if the "bug" is just a grammar/spelling error in both English and Vietnamese. We try to make our products as perfect as possible.
-
-## Screenshots
-
-1. The settings page under WooCommerce -> Woo Viet.
-2. Prices are changed to "K", and the symbol is now "VND".
-3. List provinces when selecting Vietnam.
-4. Let clients know about the currency conversion before switching to the PayPal pages.
-
## Changelog
+### 1.4 - 2018.04.24
+
+* Fix the on-hold order issue with PayPal Standard.
+* Fix the issue in OnePay Domestic gateway when users cancel payment.
+* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address.
+* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
+* Add "Settings" link in the Plugins list page when the plugin is active.
+
### 1.3.1 - 2017.07.09
+
* Improve the OnePay domestic gateway.
* Add the plugin icon and banner.
* Add the questionnaire after 4 weeks of installation.
diff --git a/readme.txt b/readme.txt
index 693ff4c..08942d3 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,9 +1,10 @@
=== Woo Viet - WooCommerce for Vietnam ===
-Contributors: htdat, thup90
+Contributors: htdat, thup90, longnguyen
Tags: OnePay WooCommerce, OnePay Vietnam, WooCommerce Vietnam, vietnam, vietnamese, vietnam provinces, paypal for vietnam dong, vnd, vietnam dong, vietnam currency, vietnam customization
Requires at least: 4.3
-Tested up to: 4.8
-Stable tag: 1.3.1
+Tested up to: 4.9.5
+Requires PHP: 5.6
+Stable tag: 1.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -21,17 +22,17 @@ Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/).
= FEATURES =
* Change the VND currency symbol `đ` to anything, e.g: `VND`, `VNĐ`, `đồng`, etc.
-* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. This is not available in WooCommerce by default.
+* Add provinces for Vietnam when visitors select Vietnam as a country of the shipping (billing) address. Arrange the address fields to the Vietnam standard: Country - Province - District - Address.
* Add districts to Vietnam provinces.
* Convert `000` of prices to `K` (or anything). E.g: `50000` (VND) will be `50K` (VND), or `50 thousand` (VND).
* Support `VND` for [the PayPal Standard gateway](https://docs.woocommerce.com/document/paypal-standard/). Convert `VND` prices to any PayPal supported currency before sending visitors to the PayPal pages.
+* Support `VND` for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/)
* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/). Implement all methods in [the official documents](https://mtf.onepay.vn/developer/?page=modul_noidia_php): QueryDR, IPN, and Return URL.
= ROAD MAP =
In the future, this plugin will add more and more features for the Vietnam market:
-* Integrate all districts to Vietnam provinces. (available since 1.2)
* Integrate at least one solution for collecting money by phone cards.
* Integrate the Vietnam payment gateways like 1Pay, OnePay, BaoKim, Ngan Luong, etc.
* Integrate the Vietnam shipping solutions like ShipChung, Giaohangnhanh, ViettelPost, etc.
@@ -75,30 +76,24 @@ Follow these steps to install and use the plugin:
== Changelog ==
-= 1.3.1 - 2017.07.09 =
-* Improve the OnePay domestic gateway.
-* Add the plugin icon and banner.
-* Add the questionnaire after 4 weeks of installation.
+= 1.4 - 2018.04.24 =
-= 1.3 - 2017.04.22 =
-* Add [the OnePay domestic (local ATM cards) gateway](http://onepay.com.vn/).
+* Fix the on-hold order issue with PayPal Standard.
+* Fix the issue in OnePay Domestic gateway when users cancel payment.
+* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address.
+* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
+* Add "Settings" link in the Plugins list page when the plugin is active.
-= 1.2 - 2017.03.03 =
-* Integrate all districts to Vietnam provinces. Credits: [WC City Select by 8manos](https://github.com/8manos/wc-city-select) and [the Vietnam district data by 10h30](https://github.com/htdat/woo-viet/issues/4#issuecomment-277449462)
-
-= 1.1 =
-* Replace all “WooCommerce for Vietnam” to “Woo Viet”
-* Replace all “woocomerce-for-vietnam” to “woo-viet”
-* Re-upload to WordPress.org
-
-= 1.0 =
-* First release.
-* Upload to WordPress.org
+See all change logs on [GitHub repo](https://github.com/htdat/woo-viet#changelog).
== Upgrade Notice ==
+= 1.4 =
+
+Version 1.4 arranges the address fields to the Vietnam standard (Country - Province - District - Address), supports VND for PayPal Express Checkout, and fixes issues on PayPal Standard and OnePay Domestic gateways.
+
= 1.3 =
-The new version 1.2 comes with the feature "Add the OnePay domestic (local ATM cards) gateway]"
+The new version 1.3 comes with the feature "Add the OnePay domestic (local ATM cards) gateway]"
= 1.2 =
The new version 1.2 comes with the feature "Add districts to Vietnam provinces".
diff --git a/woo-viet.php b/woo-viet.php
index 60f0403..b81dc74 100644
--- a/woo-viet.php
+++ b/woo-viet.php
@@ -7,7 +7,11 @@
* Author URI: https://profiles.wordpress.org/htdat
* Text Domain: woo-viet
* Domain Path: /languages
- * Version: 1.3.1
+ * Version: 1.4
+ *
+ * WC requires at least: 2.6
+ * WC tested up to: 2.3
+ *
* License: GPLv2+
*/
@@ -64,6 +68,12 @@ class WooViet {
array(
'enabled' => 'yes',
),
+ 'vnd_paypal_express_checkout' =>
+ array(
+ 'enabled' => 'yes',
+ 'currency' => 'USD',
+ 'rate' => '22770',
+ ),
);
/**
* The properties to manage all classes under the "inc/" folder
@@ -76,6 +86,7 @@ class WooViet {
protected $Currency;
protected $VND_PayPal_Standard;
protected $Admin_Page;
+ protected $VND_PayPal_Express_Checkout;
/**
* Setup class.
@@ -90,7 +101,7 @@ class WooViet {
* Throw a notice if WooCommerce is NOT active
*/
public function notice_if_not_woocommerce() {
- $class = 'notice notice-error';
+ $class = 'notice notice-warning';
$message = __( 'Woo Viet is not running because WooCommerce is not active. Please activate both plugins.',
'woo-viet' );
@@ -109,6 +120,9 @@ class WooViet {
if ( class_exists( 'WooCommerce' ) ) {
// Run this plugin normally if WooCommerce is active
$this->main();
+
+ // Add "Settings" link when the plugin is active
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_settings_link' ) ) ;
} else {
// Throw a notice if WooCommerce is NOT active
add_action( 'admin_notices', array( $this, 'notice_if_not_woocommerce' ) );
@@ -196,6 +210,15 @@ class WooViet {
);
}
+ // Check if "Support VND for the PayPal Express Checkout gateway" is enabled
+ if ( 'yes' == $settings['vnd_paypal_express_checkout']['enabled'] ) {
+ include( WOO_VIET_DIR . 'inc/class-wooviet-vnd-paypal-express-checkout.php' );
+ $this->VND_PayPal_Express_Checkout = new WooViet_VND_PayPal_Express_Checkout(
+ $settings['vnd_paypal_express_checkout']['rate'],
+ $settings['vnd_paypal_express_checkout']['currency']
+ );
+ }
+
}
/**
@@ -224,4 +247,17 @@ class WooViet {
}
-}
\ No newline at end of file
+ /**
+ * Add "Settings" link in the Plugins list page when the plugin is active
+ *
+ * @since 1.4
+ * @author Longkt
+ */
+ public function add_settings_link( $links ) {
+ $settings = array( '' . __( 'Settings', 'woo-viet' ) . '' );
+ $links = array_reverse( array_merge( $links, $settings ) );
+
+ return $links;
+ }
+
+}