wpmlNotices = $wpmlNotices; } public function add_hooks() { add_action( 'admin_notices', [ $this, 'addNotice' ] ); add_action( 'woocommerce_after_order_object_save', [ $this, 'onNewOrder' ] ); } public function addNotice() { if ( $this->shouldDisplayNotice() ) { $notice = $this->wpmlNotices->get_new_notice( 'wcml-rate', $this->getNoticeText(), 'wcml-admin-notices' ); if ( $this->wpmlNotices->is_notice_dismissed( $notice ) ) { return; } $notice->set_css_class_types( 'info' ); $notice->set_css_classes( [ 'otgs-notice-wcml-rating' ] ); $notice->set_dismissible( true ); $reviewLink = 'https://wordpress.org/support/plugin/woocommerce-multilingual/reviews/?filter=5#new-post'; $reviewButton = $this->wpmlNotices->get_new_notice_action( __( 'Review WooCommerce Multilingual & Multicurrency', 'woocommerce-multilingual' ), $reviewLink, false, false, true ); $notice->add_action( $reviewButton ); $notice->set_restrict_to_screen_ids( RestrictedScreens::get() ); $notice->add_capability_check( [ 'manage_options', 'wpml_manage_woocommerce_multilingual' ] ); $this->wpmlNotices->add_notice( $notice ); } } /** * @return string */ private function getNoticeText() { $text = '
';
$text .= __( 'How do you feel getting your very first order in foreign language or currency?', 'woocommerce-multilingual' );
$text .= '
';
$text .= __( 'We for sure are super thrilled about your success! Will you help WCML improve and grow?', 'woocommerce-multilingual' );
$text .= '
'; $text .= __( 'Give us review now.', 'woocommerce-multilingual' ); $text .= '
'; return $text; } /** * @return bool */ private function shouldDisplayNotice() { return get_option( self::OPTION_NAME, false ); } /** * @param \WC_Order $order */ public function onNewOrder( $order ) { if ( ! $this->shouldDisplayNotice() ) { $this->maybeAddOptionToShowNotice( $order ); } } /** * @param \WC_Order $order */ private function maybeAddOptionToShowNotice( $order ) { $isOrderInSecondLanguage = $order->get_meta( 'wpml_language' ) !== apply_filters( 'wpml_default_language', '' ); $isOrderInSecondCurrency = wcml_is_multi_currency_on() && $order->get_currency() !== wcml_get_woocommerce_currency_option(); if ( $isOrderInSecondLanguage || $isOrderInSecondCurrency ) { add_option( self::OPTION_NAME, true ); } } }