admin-menus
1 month ago
currencies
1 month ago
template-classes
1 month ago
translation-editor
1 month ago
class-wcml-ajax-setup.php
1 month ago
class-wcml-attributes.php
1 month ago
class-wcml-capabilities.php
1 month ago
class-wcml-cart-removed-items-widget.php
1 year ago
class-wcml-cart-switch-lang-functions.php
1 month ago
class-wcml-cart-sync-warnings.php
1 month ago
class-wcml-cart.php
1 month ago
class-wcml-comments.php
1 month ago
class-wcml-compatibility.php
1 month ago
class-wcml-coupons.php
1 month ago
class-wcml-dependencies.php
1 month ago
class-wcml-emails.php
1 month ago
class-wcml-endpoints.php
1 month ago
class-wcml-install.php
1 month ago
class-wcml-languages-upgrader.php
1 month ago
class-wcml-locale.php
1 month ago
class-wcml-orders.php
1 month ago
class-wcml-products-screen-options.php
1 month ago
class-wcml-products.php
1 month ago
class-wcml-reports.php
1 month ago
class-wcml-requests.php
1 month ago
class-wcml-resources.php
1 month ago
class-wcml-store-pages.php
1 month ago
class-wcml-terms.php
1 month ago
class-wcml-tp-support.php
1 month ago
class-wcml-troubleshooting.php
1 month ago
class-wcml-upgrade.php
1 month ago
class-wcml-url-translation.php
1 month ago
class-wcml-wc-gateways.php
1 month ago
class-wcml-wc-shipping.php
1 month ago
class-wcml-wc-strings.php
1 month ago
class-wcml-widgets.php
1 month ago
constants.php
1 month ago
functions-pure.php
1 month ago
functions.php
1 month ago
installer-loader.php
1 month ago
missing-php-functions.php
1 month ago
wcml-core-functions.php
1 month ago
wcml-switch-lang-request.php
1 month ago
class-wcml-cart-sync-warnings.php
120 lines
| 1 | <?php |
| 2 | |
| 3 | class WCML_Cart_Sync_Warnings { |
| 4 | |
| 5 | const KEY_DISMISS = 'dismiss_cart_warning'; |
| 6 | |
| 7 | private $woocommerce_wpml; |
| 8 | private $sitepress; |
| 9 | private $extensions_list = [ |
| 10 | 'WC_Subscriptions' => 'Woocommerce Subscriptions', |
| 11 | 'WC_Product_Addons' => 'Woocommerce Product Addons', |
| 12 | 'WC_Bookings' => 'Woocommerce Bookings', |
| 13 | 'WC_Accommodation_Bookings_Plugin' => 'Woocommerce Accommodation Bookings', |
| 14 | 'WC_Product_Bundle' => 'Woocommerce Product Bundles', |
| 15 | 'WC_Composite_Products' => 'Woocommerce Composite Products', |
| 16 | 'RP_WCDPD' => 'WooCommerce Dynamic Pricing & Discounts', |
| 17 | ]; |
| 18 | |
| 19 | public function __construct( $woocommerce_wpml, $sitepress ) { |
| 20 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 21 | $this->sitepress = $sitepress; |
| 22 | } |
| 23 | |
| 24 | public function add_hooks() { |
| 25 | |
| 26 | if ( $this->check_if_show_notices_needed() ) { |
| 27 | add_action( 'admin_notices', [ $this, 'show_cart_notice' ] ); |
| 28 | add_action( 'admin_enqueue_scripts', [ $this, 'register_styles' ] ); |
| 29 | } |
| 30 | |
| 31 | add_action( 'admin_init', [ $this, 'handle_dismiss_cart_notice' ] ); |
| 32 | } |
| 33 | |
| 34 | public function check_if_show_notices_needed() { |
| 35 | |
| 36 | $cart_sync_settings = $this->woocommerce_wpml->settings['cart_sync']; |
| 37 | |
| 38 | if ( |
| 39 | ( |
| 40 | $cart_sync_settings['lang_switch'] === $this->sitepress->get_wp_api()->constant( 'WCML_CART_SYNC' ) || |
| 41 | $cart_sync_settings['currency_switch'] === $this->sitepress->get_wp_api()->constant( 'WCML_CART_SYNC' ) |
| 42 | ) && |
| 43 | ! $this->woocommerce_wpml->settings[self::KEY_DISMISS] && |
| 44 | $this->get_list_of_active_extensions() |
| 45 | ) { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | return false; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | public function register_styles() { |
| 54 | wp_enqueue_style( 'wcml-cart-warning', $this->sitepress->get_wp_api()->constant( 'WCML_PLUGIN_URL' ) . '/res/css/wcml-cart-warning.css' ); |
| 55 | } |
| 56 | |
| 57 | public function show_cart_notice() { |
| 58 | $list_of_extensions = $this->get_list_of_active_extensions(); |
| 59 | $request_url = esc_url( $_SERVER['REQUEST_URI'] ); |
| 60 | |
| 61 | $admin_settings_url = esc_url( \WCML\Utilities\AdminUrl::getSettingsTab() . '#cart' ); |
| 62 | $documentation_link = esc_url( WCML_Tracking_Link::getWcmlClearCartDoc() ); |
| 63 | |
| 64 | $reset_cart_strings[] = esc_html_x( 'Because of some elements in your site configuration, when the users switch the currency or the language on the front end, the cart content might not be synchronized correctly.', 'Reset cart option warning 1', 'woocommerce-multilingual' ); |
| 65 | /* translators: %s is link to "reset cart configuration" */ |
| 66 | $reset_cart_strings[] = esc_html_x( 'It is recommended that you %s with the option to reset the cart in a situation like this.', 'Reset cart option warning 2', 'woocommerce-multilingual' ); |
| 67 | |
| 68 | $reset_cart_configure_link = '<strong><a href="' . $admin_settings_url . '">' . esc_html__( 'configure WPML Multilingual & Multicurrency for WooCommerce', 'woocommerce-multilingual' ) . '</a></strong>'; |
| 69 | |
| 70 | $reset_cart_message = $reset_cart_strings[0]; |
| 71 | $reset_cart_message .= '</p>'; |
| 72 | $reset_cart_message .= $list_of_extensions; |
| 73 | $reset_cart_message .= '<p>'; |
| 74 | $reset_cart_message .= $reset_cart_strings[1]; |
| 75 | $reset_cart_message .= '<strong><a href="' . $documentation_link . '" target="_blank">' . esc_html__( 'More details', 'woocommerce-multilingual' ) . '</a></strong>'; |
| 76 | |
| 77 | $message = '<div class="message error otgs-is-dismissible">'; |
| 78 | $message .= '<p>'; |
| 79 | $message .= sprintf( $reset_cart_message, $reset_cart_configure_link ); |
| 80 | $message .= '</p>'; |
| 81 | $message .= '<a class="notice-dismiss" href="' . esc_url( add_query_arg( 'wcml_action', self::KEY_DISMISS, $request_url ) ) . '"><span class="screen-reader-text">' . esc_html__( 'Dismiss', 'woocommerce-multilingual' ) . '</span></a>'; |
| 82 | $message .= '</div>'; |
| 83 | |
| 84 | echo $message; |
| 85 | } |
| 86 | |
| 87 | public function get_list_of_active_extensions() { |
| 88 | |
| 89 | $html = ''; |
| 90 | |
| 91 | foreach ( $this->extensions_list as $extension_class => $display_name ) { |
| 92 | |
| 93 | if ( class_exists( $extension_class ) ) { |
| 94 | |
| 95 | if ( empty( $html ) ) { |
| 96 | $html .= '<ul>'; |
| 97 | } |
| 98 | |
| 99 | $html .= '<li>' . $display_name . '</li>'; |
| 100 | |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if ( ! empty( $html ) ) { |
| 105 | $html .= '</ul>'; |
| 106 | } |
| 107 | |
| 108 | return $html; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | public function handle_dismiss_cart_notice() { |
| 113 | if ( isset( $_GET['wcml_action'] ) && $_GET['wcml_action'] === self::KEY_DISMISS ) { |
| 114 | $this->woocommerce_wpml->settings[self::KEY_DISMISS] = true; |
| 115 | $this->woocommerce_wpml->update_settings(); |
| 116 | wcml_safe_redirect( remove_query_arg( 'wcml_action' ) ); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 |