diff --git a/bootstrap.php b/bootstrap.php index 943cc999..63786eda 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,6 +5,19 @@ use function NewfoldLabs\WP\ModuleLoader\register; +define( 'NFD_WOOCOMMERCE_MODULE_VERSION', '1.3.26' ); + +if ( function_exists( 'is_admin' ) && is_admin() ) { + $old_woocommerce_module_version = get_option( 'nfd_woocommerce_module_version' ); + + if ( $old_woocommerce_module_version < NFD_WOOCOMMERCE_MODULE_VERSION ) { + update_option( 'nfd_woocommerce_module_version', NFD_WOOCOMMERCE_MODULE_VERSION, true ); + } +} + +/** + * Skips woocommerce onboarding + */ function skip_woo_onboarding() { $wc_option = 'woocommerce_onboarding_profile'; $skip_onboarding = array( diff --git a/src/components/PayPalButton.js b/src/components/PayPalButton.js new file mode 100644 index 00000000..cdecb5b8 --- /dev/null +++ b/src/components/PayPalButton.js @@ -0,0 +1,20 @@ +import {useEffect, useRef} from '@wordpress/element'; + +const PaypalButton = () => { + const ppButton = useRef(); + + useEffect(() => { + const paypalBtn = document.querySelector('.yith-btn-paypal'); + paypalBtn && ppButton.current.appendChild(paypalBtn); + return () => { + const hiddenWrapper = document.querySelector('.yith-ppcp-hidden-button-wrapper'); + hiddenWrapper && hiddenWrapper.appendChild(paypalBtn); + }; + }, []); + + return ( +
+ ); +}; + +export default PaypalButton; \ No newline at end of file diff --git a/src/components/Paypal.js b/src/components/Paypal.js index a78b1f47..ddc98569 100644 --- a/src/components/Paypal.js +++ b/src/components/Paypal.js @@ -1,5 +1,4 @@ -import { Badge, Button, Title, Link } from "@newfold/ui-component-library"; -import { useEffect } from "@wordpress/element"; +import { Badge, Button, Title } from "@newfold/ui-component-library"; import { __ } from "@wordpress/i18n"; import classNames from "classnames"; import { ReactComponent as AmexBrand } from "../icons/brands/amex.svg"; @@ -12,153 +11,122 @@ import { ReactComponent as SofortBrand } from "../icons/brands/sofort.svg"; import { ReactComponent as VenmoBrand } from "../icons/brands/venmo.svg"; import { ReactComponent as VisaBrand } from "../icons/brands/visa.svg"; import { ThirdPartyIntegration } from "./ThirdPartyIntegration"; +import PayPalButton from "./PayPalButton"; const Paypal = ({ notify }) => { - useEffect(() => { - const ppButton = document.querySelector( ".yith-btn-paypal" ); - if( ppButton ){ - (function( d, s, id ) { - var js, ref = d.getElementsByTagName( s )[0]; - if ( !d.getElementById( id ) ) { - js = d.createElement( s ); - js.id = id; - js.async = true; - js.src = "https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js"; - ref.parentNode.insertBefore( js, ref ); - } - }( document, "script", "paypal-js" )); - window?.PAYPAL?.apps?.Signup?.loadScripts( document, "script" ); - window?.PAYPAL?.apps?.Signup?.render(); - } - return ()=>{ - const panel = document.querySelector( '#payment-details' ); - if( !panel && ppButton ){ - ppButton.remove(); - } - }; - }); return ( - - {({ integrationStatus, onConnect, isInstalling }) => { - const isSetupComplete = integrationStatus?.complete; - const environment = integrationStatus?.details?.environment; - return ( -
-
+ {({ integrationStatus, onConnect, isInstalling }) => { + const isSetupComplete = integrationStatus?.complete; + const environment = integrationStatus?.details?.environment; + return ( +
+
+ + {isInstalling ? ( + + ) : isSetupComplete ? ( + + ) : typeof yith_ppwc_login !== "undefined" && + !parseInt(yith_ppwc_login?.liveConnected) ? ( + + ) : ( + + )} +
+ {isSetupComplete && environment && ( +
+ {__("Environment:", "wp-module-ecommerce")} + - - {isInstalling ? ( - - ) : isSetupComplete ? ( - - ) : typeof yith_ppwc_login !== "undefined" && - !parseInt(yith_ppwc_login?.liveConnected) ? ( - - {__("Connect", "wp-module-ecommerce")} - - ) : ( - + {environment} + +
+ )} + {!isSetupComplete && ( +
+ + {__("Provides flexible checkout options", "wp-module-ecommerce")} + +
    +
  • {__("PayPal Buy Now Pay Later", "wp-module-ecommerce")}
  • +
  • {__("White-Labeling", "wp-module-ecommerce")}
  • +
  • + {__( + "Country-specific payment methods", + "wp-module-ecommerce", + )} +
  • +
+ + {__( + " Supports many popular payment methods", + "wp-module-ecommerce", )} + +
+ + + + + + + +
- {isSetupComplete && environment && ( -
- {__("Environment:", "wp-module-ecommerce")} - - {environment} - -
- )} - {!isSetupComplete && ( -
- - {__("Provides flexible checkout options", "wp-module-ecommerce")} - -
    -
  • {__("PayPal Buy Now Pay Later", "wp-module-ecommerce")}
  • -
  • {__("White-Labeling", "wp-module-ecommerce")}
  • -
  • - {__( - "Country-specific payment methods", - "wp-module-ecommerce" - )} -
  • -
- - {__( - " Supports many popular payment methods", - "wp-module-ecommerce" - )} - -
- - - - - - - - -
-
- )}
- ); - }} - + )} +
+ ); + }} + ); }; export default Paypal; diff --git a/src/sdk/woocommerce.js b/src/sdk/woocommerce.js index 1ae04c0a..653b79b2 100644 --- a/src/sdk/woocommerce.js +++ b/src/sdk/woocommerce.js @@ -7,7 +7,7 @@ import { WordPressSdk } from "./wordpress"; const Endpoints = { ORDERS: (period) => NewfoldRuntime.createApiUrl("/wc/v3/orders", period), ALL_TIME_ORDERS: NewfoldRuntime.createApiUrl("/wc/v3/orders"), - PRODUCTS: NewfoldRuntime.createApiUrl("/wc/v3/products"), + PRODUCTS: NewfoldRuntime.createApiUrl("/wc/store/products"), Analytics: { JETPACK: (range) => NewfoldRuntime.createApiUrl("/jetpack/v4/module/stats/data", { range }), @@ -111,7 +111,7 @@ export const WooCommerceSdk = { visitors: [this_period[visitorsIndex], prior_period[visitorsIndex]], }; } - return { views: [], visitors: [] }; + return { views: [], visitors: [] }; }, async sales(period) { if (NewfoldRuntime.isWoo) { @@ -142,7 +142,7 @@ export const WooCommerceSdk = { }, async get() { if (NewfoldRuntime.isWoo) { - return apiFetch({ url: Endpoints.ALL_TIME_ORDERS }); + return apiFetch({ url: Endpoints.ALL_TIME_ORDERS }); } }, },