getId($attrs); if ($id === null) { return ''; } $campaign = new Campaign($id); $campaign->loadSettings(); // Don't render the shortcode if the campaign's inactive. if ( ! $campaign->isActive() || $campaign->isScheduled() || ! $campaign->showStickyBarOn($this->getCurrentPageId()) ) { return ''; } // We must check if the campaign is sticky // If yes, we don't need to run actions as the campaign is no longer active. // Running actions for dismissed campaigns is bad for UX, so we avoid it. if($campaign->isDismissed()){ return ''; } // If it's a regular campaign and expired, run selected actions. if ($campaign->isRegular() && $campaign->isExpired()) { $actionManager = new ActionManager($campaign); $actionManager->run(); } $template = apply_filters('hurryt_campaign_template', $campaign->buildTemplate()); return $template === '' ? '': $campaign->wrapTemplate($template); } /** * Returns campaign ID if set. * * @param $attrs * * @return int|null */ function getId($attrs) { if ( ! $this->hasId($attrs)) { return null; } $id = intval($attrs['id']); if ( ! $this->campaignExists($id)) { return null; } return $id; } function getCurrentPageId() { $objectId = get_queried_object_id(); if(! Utils\Helpers::isWcActive()){ return $objectId; } $wcIds = [ 'shop' => get_option('woocommerce_shop_page_id'), 'cart' => get_option('woocommerce_cart_page_id'), 'checkout' => get_option('woocommerce_checkout_page_id'), 'checkout_pay' => get_option('woocommerce_pay_page_id'), 'thanks' => get_option('woocommerce_thanks_page_id'), 'myaccount' => get_option('woocommerce_myaccount_page_id'), 'edit_address' => get_option('woocommerce_edit_address_page_id'), 'view_order' => get_option('woocommerce_view_order_page_id'), 'terms' => get_option('woocommerce_terms_page_id'), ]; if (is_shop()) { $objectId = $wcIds['shop']; } elseif (is_account_page()) { $objectId = $wcIds['myaccount']; } elseif (is_checkout_pay_page()) { $objectId = $wcIds['checkout_pay']; } elseif (is_checkout()) { $objectId = $wcIds['checkout']; } elseif (is_cart()) { $objectId = $wcIds['cart']; } elseif (is_view_order_page()) { $objectId = $wcIds['view_order']; } elseif (is_view_order_page()) { $objectId = $wcIds['view_order']; } elseif (is_view_order_page()) { $objectId = $wcIds['view_order']; } elseif (is_view_order_page()) { $objectId = $wcIds['view_order']; } return $objectId; } /** * Verify if the given attributes contain the campaign ID. * * @param $attrs * * @return bool */ function hasId($attrs) { return isset($attrs['id']); } /** * Verify if the given campaign exists in database. * * @param $id * * @return boolean */ function campaignExists($id) { return get_post($id) instanceof WP_Post; } }