constant that tells the plugin is active, and default link. */ private const PRODUCTS = array( 'shipping' => array( 'CNWSCHECKOUT_PRO_VERSION', 'https://web-style.dk/vare/checkout-optimizer-pro/' ), 'newsletter' => array( 'CNWS_MAIL_VERSION', 'https://web-style.dk/woocommerce-nyhedsbrev/' ), 'accounting' => array( 'CNWS_ACCOUNTING_VERSION', 'https://web-style.dk/woocommerce-regnskabsintegration/' ), ); /** * Promotions to show the current user, all in the guide's discount step where they explain a next * step: 'accounting' under the discount (bookkeeping), 'shipping' under how shipping is calculated * and 'newsletter' under sending personal codes. * * @return array */ public function visible(): array { $dismissed = $this->dismissed(); $visible = array(); foreach ( self::PRODUCTS as $key => list( $constant, $link ) ) { // The shipping text explains why the code cannot change shipping, so it stays while Checkout // Optimizer Pro is active but does not handle the code (an older version or no free_shipping // entitlement); a Pro that handles it replaces the whole text with its own settings. if ( in_array( $key, $dismissed, true ) || ( defined( $constant ) && 'shipping' !== $key ) ) { continue; } $visible[ $key ] = $this->copy( $key ) + array( /** * Link of a promotion, e.g. to a reseller's page. * * @param string $link Default link on web-style.dk. * @param string $key shipping, newsletter or accounting. */ 'link' => esc_url_raw( (string) apply_filters( 'cnwscoupons_promotion_link', $link, $key ) ), ); } return $visible; } /** * @param string $key Promotion key. */ public function dismiss( string $key ): void { if ( ! isset( self::PRODUCTS[ $key ] ) ) { return; } $dismissed = $this->dismissed(); if ( ! in_array( $key, $dismissed, true ) ) { $dismissed[] = $key; update_user_meta( get_current_user_id(), self::META, $dismissed ); } } /** * @return string[] */ private function dismissed(): array { $dismissed = get_user_meta( get_current_user_id(), self::META, true ); return is_array( $dismissed ) ? array_values( array_filter( $dismissed, 'is_string' ) ) : array(); } /** * A pitch: the question the shop has at that point, one line on the answer and a button. * * @param string $key Promotion key. * @return array{title: string, text: string, label: string} */ private function copy( string $key ): array { switch ( $key ) { case 'shipping': return array( 'title' => __( 'Want to control shipping with the code?', 'webstyle-coupons' ), 'text' => defined( 'CNWSCHECKOUT_PRO_VERSION' ) ? __( 'Your Checkout Optimizer Pro does not control shipping for discount codes yet. Update it to the latest version and make sure your license includes free shipping.', 'webstyle-coupons' ) : __( 'Want these options? Use our checkout plugin Checkout Optimizer Pro – it controls shipping, also for discount codes.', 'webstyle-coupons' ), 'label' => __( 'See Checkout Optimizer Pro', 'webstyle-coupons' ), ); case 'newsletter': return array( 'title' => __( 'Send the codes as a newsletter?', 'webstyle-coupons' ), 'text' => __( 'WebStyle Mail puts each recipient\'s own code in the e-mail – no CSV files, no copying.', 'webstyle-coupons' ), 'label' => __( 'See WebStyle Mail', 'webstyle-coupons' ), ); default: return array( 'title' => __( 'Discounts straight into your bookkeeping?', 'webstyle-coupons' ), 'text' => __( 'WebStyle Accounting Sync posts orders and discounts to e-conomic, Dinero, Billy and more.', 'webstyle-coupons' ), 'label' => __( 'See Accounting Sync', 'webstyle-coupons' ), ); } } }