diff --git a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php index d8af8ff10de..4742687f6ab 100644 --- a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php +++ b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php @@ -63,6 +63,83 @@ class OnboardingTasks { add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_homepage_notice_admin_script' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_tax_notice_admin_script' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'add_onboarding_product_import_notice_admin_script' ) ); + + // Update payment cache on payment gateways update. + add_action( 'update_option_woocommerce_stripe_settings', array( $this, 'check_stripe_completion' ), 10, 2 ); + add_action( 'add_option_woocommerce_stripe_settings', array( $this, 'check_stripe_completion' ), 10, 2 ); + add_action( 'update_option_woocommerce_ppec_paypal_settings', array( $this, 'check_paypal_completion' ), 10, 2 ); + add_action( 'add_option_woocommerce_ppec_paypal_settings', array( $this, 'check_paypal_completion' ), 10, 2 ); + add_action( 'add_option_wc_square_refresh_tokens', array( $this, 'check_square_completion' ), 10, 2 ); + } + + /** + * Check if Square payment settings are complete. + * + * @param string $option Option name. + * @param array $value Current value. + */ + public static function check_square_completion( $option, $value ) { + if ( empty( $value ) ) { + return; + } + + self::maybe_update_payments_cache(); + } + + + /** + * Check if Paypal payment settings are complete. + * + * @param mixed $old_value Old value. + * @param array $value Current value. + */ + public static function check_paypal_completion( $old_value, $value ) { + if ( + ! isset( $value['enabled'] ) || + 'yes' !== $value['enabled'] || + ! isset( $value['api_username'] ) || + empty( $value['api_username'] ) || + ! isset( $value['api_password'] ) || + empty( $value['api_password'] ) + ) { + return; + } + + self::maybe_update_payments_cache(); + } + + /** + * Check if Stripe payment settings are complete. + * + * @param mixed $old_value Old value. + * @param array $value Current value. + */ + public static function check_stripe_completion( $old_value, $value ) { + if ( + ! isset( $value['enabled'] ) || + 'yes' !== $value['enabled'] || + ! isset( $value['publishable_key'] ) || + empty( $value['publishable_key'] ) || + ! isset( $value['secret_key'] ) || + empty( $value['secret_key'] ) + ) { + return; + } + + self::maybe_update_payments_cache(); + } + + /** + * Update the payments cache to complete if not already. + */ + public static function maybe_update_payments_cache() { + $task_list_payments = get_option( 'woocommerce_task_list_payments', array() ); + if ( isset( $task_list_payments['completed'] ) && $task_list_payments['completed'] ) { + return; + } + + $task_list_payments['completed'] = 1; + update_option( 'woocommerce_task_list_payments', $task_list_payments ); } /**