wcml = $wcml; $this->notices = $notices; } /** * Add hooks to manage visibility of notice. */ public function add_hooks() { $notice = $this->notices->get_notice( self::NOTICE_ID ); $needsNotice = wcml_is_multi_currency_on() && $this->hasOneUniqueCurrency(); if ( $needsNotice && ! $notice ) { add_action( 'admin_init', [ $this, 'addNotice' ] ); } elseif ( ! $needsNotice && $notice ) { add_action( 'admin_init', [ $this, 'removeNotice' ] ); } } /** * Add a notice reminding admin about missing secondary currency. */ public function addNotice() { $text = '

' . __( "You haven't added any secondary currencies", 'woocommerce-multilingual' ) . '

'; $text .= '

' . __( "Please add another currency to fully utilize multicurrency mode. If you do not need multiple currencies, you can disable this setting to improve your site's performance.", 'woocommerce-multilingual' ) . '

'; $text .= '' . __( 'Configure multicurrency mode', 'woocommerce-multilingual' ) . ''; $notice = $this->notices->create_notice( self::NOTICE_ID, $text ); $notice->set_css_class_types( 'notice-warning' ); $notice->set_restrict_to_screen_ids( RestrictedScreens::get() ); $notice->set_dismissible( true ); $this->notices->add_notice( $notice ); } /** * Remove the notice if the problem has been fixed */ public function removeNotice() { $notice = $this->notices->get_notice( self::NOTICE_ID ); $this->notices->remove_notice( $notice->get_group(), $notice->get_id() ); } /** * @return bool */ private function hasOneUniqueCurrency() { return count( (array) Obj::path( [ 'settings', 'currency_options' ], $this->wcml ) ) <= 1; } }