container = $container; parent::__construct( self::GROUP_COUNT, self::TEST_NAME, $container ); $this->override_id_for_old_user( $container ); } /** * Clears info about variant and draws again */ public function reset() { parent::reset(); $this->override_id_for_old_user( $this->container ); } /** * If old user then should have static group * * @param PersistentContainer $container Persistent container. */ private function override_id_for_old_user( PersistentContainer $container ) { if ( self::VARIANT_ID_FOR_OLD_INSTALLATION !== $this->current_variant_id && $this->is_old_installation() ) { $this->current_variant_id = self::VARIANT_ID_FOR_OLD_INSTALLATION; $container->set( $this->get_container_key(), self::VARIANT_ID_FOR_OLD_INSTALLATION ); } } /** * If this a old user? If so then FS should work like always. * * @return bool */ private function is_old_installation() { return strtotime( self::NEW_USER_AFTER_THIS_DATE ) > $this->activation_date_according_to_wpdesk_helper(); } /** * Activation date according to wpdesk helper. * * @return int timestamp */ private function activation_date_according_to_wpdesk_helper() { $option_name = 'plugin_activation_flexible-shipping/flexible-shipping.php'; $activation_date = get_option( $option_name, current_time( 'mysql' ) ); if ( ! $activation_date ) { return time(); } return strtotime( $activation_date ); } /** * Get variant. * * @return ABVariant */ public function get_variant() { switch ( $this->current_variant_id ) { case self::VARIANT_WITH_CONTACT_INFORMATION_ON_TOP: return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Top(); case self::VARIANT_WITH_CONTACT_INFORMATION_ON_BOTTOM: return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Bottom(); case self::VARIANT_WITH_CONTACT_BUTTON: return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_Button(); default: return new WPDesk_Flexible_Shipping_AB_Variant_Old(); } } }