CachePlugins.php
1 week ago
CurrencySwitcherUseTwigTemplate.php
1 week ago
ExportImport.php
1 week ago
MultiCurrencyMissing.php
1 week ago
RestrictedScreens.php
1 week ago
Review.php
1 week ago
TranslationControlMovedNotice.php
1 week ago
WizardNotice.php
1 week ago
Review.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\AdminNotices; |
| 4 | |
| 5 | use WCML\StandAlone\IStandAloneAction; |
| 6 | use WPML_Notices; |
| 7 | use IWPML_Backend_Action; |
| 8 | use IWPML_Frontend_Action; |
| 9 | use IWPML_DIC_Action; |
| 10 | use function WCML\functions\isStandAlone; |
| 11 | |
| 12 | class Review implements IWPML_Backend_Action, IWPML_Frontend_Action, IWPML_DIC_Action, IStandAloneAction { |
| 13 | |
| 14 | const OPTION_NAME = 'wcml-rate-notice'; |
| 15 | |
| 16 | private $wpmlNotices; |
| 17 | |
| 18 | public function __construct( WPML_Notices $wpmlNotices ) { |
| 19 | $this->wpmlNotices = $wpmlNotices; |
| 20 | } |
| 21 | |
| 22 | public function add_hooks() { |
| 23 | if ( isStandAlone() ) { |
| 24 | add_action( 'admin_notices', [ $this, 'addNotice' ] ); |
| 25 | add_action( 'woocommerce_after_order_object_save', [ $this, 'onNewOrder' ] ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function addNotice() { |
| 30 | |
| 31 | if ( $this->shouldDisplayNotice() ) { |
| 32 | $notice = $this->wpmlNotices->get_new_notice( 'wcml-rate', $this->getNoticeText(), 'wcml-admin-notices' ); |
| 33 | |
| 34 | if ( $this->wpmlNotices->is_notice_dismissed( $notice ) ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | $notice->set_css_class_types( 'info' ); |
| 39 | $notice->set_css_classes( [ 'otgs-notice-wcml-rating' ] ); |
| 40 | $notice->set_dismissible( true ); |
| 41 | |
| 42 | $reviewLink = 'https://wordpress.org/support/plugin/woocommerce-multilingual/reviews/?filter=5#new-post'; |
| 43 | $reviewButton = $this->wpmlNotices->get_new_notice_action( esc_html__( 'Review WPML Multilingual & Multicurrency for WooCommerce', 'woocommerce-multilingual' ), $reviewLink, false, false, true ); |
| 44 | $notice->add_action( $reviewButton ); |
| 45 | |
| 46 | $notice->set_restrict_to_screen_ids( RestrictedScreens::get() ); |
| 47 | $notice->add_capability_check( [ 'manage_options', 'wpml_manage_woocommerce_multilingual' ] ); |
| 48 | $this->wpmlNotices->add_notice( $notice ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | private function getNoticeText(): string { |
| 53 | $text = '<h2>'; |
| 54 | $text .= esc_html__( 'Congrats on making your first multicurrency sale!', 'woocommerce-multilingual' ); |
| 55 | $text .= '</h2>'; |
| 56 | |
| 57 | $text .= '<p>'; |
| 58 | $text .= sprintf( |
| 59 | /* translators: %1$s and %2$s are opening and closing HTML link tags */ |
| 60 | esc_html__( 'Want to help <strong>WPML Multilingual & Multicurrency for WooCommerce</strong> plugin? %1$sGive us a review%2$s!', 'woocommerce-multilingual' ), |
| 61 | '<a href="https://wordpress.org/support/plugin/woocommerce-multilingual/reviews/?filter=5#new-post" class="wpml-external-link" target="_blank">', |
| 62 | '</a>' |
| 63 | ); |
| 64 | $text .= '</p>'; |
| 65 | |
| 66 | return $text; |
| 67 | } |
| 68 | |
| 69 | private function shouldDisplayNotice(): bool { |
| 70 | return get_option( self::OPTION_NAME, false ); |
| 71 | } |
| 72 | |
| 73 | public function onNewOrder( $order ) { |
| 74 | if ( ! $this->shouldDisplayNotice() ) { |
| 75 | $this->maybeAddOptionToShowNotice( $order ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | private function maybeAddOptionToShowNotice( \WC_Order $order ) { |
| 80 | if ( $order->is_paid() && $this->isOrderInSecondCurrency( $order ) ) { |
| 81 | add_option( self::OPTION_NAME, true ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | private function isOrderInSecondCurrency( \WC_Order $order ): bool { |
| 86 | return wcml_is_multi_currency_on() |
| 87 | && $order->get_currency() !== wcml_get_woocommerce_currency_option(); |
| 88 | } |
| 89 | } |
| 90 |