scountTypeEnabled(); } // end _isMarkupEnabledOrDiscountFromRolePrice public function getUserTotalWithSubscription($total) { return WooUserRoleModule::get('PriceSavings') ->getUserTotalWithSubscription($total); } // end getUserTotalWithSubscription public function isOnlySubscriptionInCart($cart) { $products = $cart->getProducts(); return count($products) == 1; } // end isOnlySubscriptionInCart public function getProductID($product) { $facade = &$this->ecommerceFacade; if ($this->isSubscribeVariableProduct($product)) { $idProduct = $facade->getVariationProductID($product); } else { $idProduct = $facade->getProductID($product); } return $idProduct; } // end getProductID public function isSubscribeVariableProduct($product) { return (bool) $this->ecommerceFacade->getVariationProductID($product); } // end isSubscribeVariableProduct public function getTotalRetailWithSubscription($total, $cart) { return WooUserRoleModule::get('PriceSavings') ->getTotalRetailWithSubscription($total, $cart); } // end getTotalRetailWithSubscription public function setSubscriptionProductOption($cart) { return WooUserRoleModule::get('PriceSavings') ->setSubscriptionProductOption($cart); } // end setSubscriptionProductOption public function onDisplayCustomerTotalSavingsFilter($total) { return WooUserRoleModule::get('PriceSavings') ->onDisplayCustomerTotalSavingsFilter($total); } // end onDisplayCustomerTotalSavingsFilter protected function getRetailTotal() { return WooUserRoleModule::get('PriceSavings')->getRetailTotal(); } // end getRetailTotal protected function getRetailSubTotalWithTax() { return WooUserRoleModule::get('PriceSavings') ->getRetailSubTotalWithTax(); } // end getRetailSubTotalWithTax public function onVariationPriceFilter( $price, $product, $priceRangeType, $display ) { $product = $this->getProductNewInstance($product); $userPrice = $this->getPriceByRangeType( $product, $priceRangeType, $display ); if (is_numeric($userPrice)) { $price = $this->getPriceWithFixedFloat($userPrice); } return $price; } // end onVariationPriceFilter public function getPriceByRangeType($product, $rangeType, $display) { if ($this->_isMaxPriceRangeType($rangeType)) { $price = $this->products->getMaxProductPrice($product, $display); } else { $price = $this->products->getMinProductPrice($product, $display); } return $price; } // end getPriceByRangeType private function _isMaxPriceRangeType($rangeType) { return $rangeType == PRICE_BY_ROLE_MAX_PRICE_RANGE_TYPE; } // end _isMaxPriceRangeType public function fetchPrice( $price, $type = WooUserRolePricesFrontendFestiPlugin::TYPE_PRICE_REGULAR ) { $vars = array( 'price' => $price, 'type' => $type ); return $this->fetch('price.phtml', $vars); } // end fetchRegularPrice private function _isRoleSalePriceLowerThenRolePrice($product): bool { return $this->getSalePrice($product) < $this->getPrice($product); } // end _isRoleSalePriceLowerThenRolePrice /** * Display price HTML for all product type like simple and variable. * * @param string $priceContent html content for display price * @param WC_Product $product * @return string * @throws WooUserRoleModuleException * @event woocommerce_get_price_html|woocommerce_get_variation_price_html */ public function onDisplayCustomerSavingsFilter($priceContent, $product) { if ($this->_isOneHundredPercentDiscountEnabled()) { return $this->fetch('free.phtml'); } if ($this->_hasRolePriceByVariableProduct($product) || $this->isVariableTypeProduct($product)) { if ($this->isEnableBothRegularSalePriceSetting()) { return $this->_fetchVariableBothRegularSalePrice($priceContent, $product); } return $priceContent; } $product = $this->getProductNewInstance($product); $result = WooUserRoleModule::get('PriceSavings')->hasConditionsForDisplayCustomerSavingsInProduct($product); if ($result) { return WooUserRoleModule::get('PriceSavings')->onDisplayCustomerSavingsFilter($priceContent, $product); } if ($this->_hasSalePriceForUserRole($product) && $this->_isRoleSalePriceLowerThenRolePrice($product)) { return $this->_fetchPriceAndSalePriceForUserRole($product); } if ($this->_isDisplayDefaultPriceForCustomerSavingsFilter($product)) { return $this->_fetchUserRolePrice($product); } if ($this->_hasSalePriceByDiscountOrMarkUpProduct($product)) { return $this->_fetchSimpleBothRegularSalePrice($product); } return $priceContent; } // end onDisplayPriceContentForSingleProductFilter private function _isDisplayVariableRegularPrice($product, $salePrices) { if (!$salePrices) { return false; } $min = min($salePrices); $max = max($salePrices); $facade = $this->ecommerceFacade; $productsIDs = $facade->getVariationChildrenIDs($product); return $min == $max && sizeof($productsIDs) == sizeof($salePrices); } // end _isDisplayVariableRegularPrice private function _fetchVariableBothRegularSalePrice($price, $product) { $facade = &$this->ecommerceFacade; $productsIDs = $facade->getVariationChildrenIDs($product); $regularPrices = array(); $salePrices = array(); foreach ($productsIDs as $id) { $productChild = $this->createProductInstance($id); $regularPrice = $facade->getRegularPrice($productChild); $regularPrice = $this->getPriceWithDiscountOrMarkUp( $productChild, $regularPrice, false ); $salePrice = $facade->getSalePrice($productChild); $salePrice = $this->getPriceWithDiscountOrMarkUp( $productChild, $salePrice, true ); if ($this->isIncludingTaxesToPrice()) { $regularPrice = $facade->doIncludeTaxesToPrice( $product, $regularPrice ); $salePrice = $facade->doIncludeTaxesToPrice( $product, $salePrice ); } $regularPrices[] = $regularPrice; if ($salePrice) { $salePrices[] = $salePrice; } } $regularPriceContent = false; if ($this->_isDisplayVariableRegularPrice($product, $salePrices)) { $regularPriceContent = $this->_fetchRolePriceRangeByVariableProduct( $regularPrices ); } $priceSuffix = $this->ecommerceFacade->getPriceSuffix($product); if ($salePrices) { $salePrice = min($salePrices); $salePrice = $this->getFormattedPrice($salePrice); $price = $salePrice.$priceSuffix; } if (!$regularPriceContent) { $salePriceContent = $this->_fetchRolePriceRangeByVariableProduct( $salePrices ); $price = $salePriceContent.$priceSuffix; } $vars = array( 'price' => $regularPriceContent, 'salePrice' => $price ); $content = $this->fetch( 'price_role_width_sale.phtml', $vars ); return $content; } // end _fetchVariableBothRegularSalePrice private function _fetchSimpleBothRegularSalePrice($product) { $facade = &$this->ecommerceFacade; $originalRegularPrice = $facade->getRegularPrice($product); $regularPrice = $this->getPriceWithDiscountOrMarkUp( $product, $originalRegularPrice, false ); $originalSalePrice = $facade->getSalePrice($product); $salePrice = $this->getPriceWithDiscountOrMarkUp( $product, $originalSalePrice ); if ($this->isIncludingTaxesToPrice()) { $regularPrice = $facade->doIncludeTaxesToPrice( $product, $regularPrice ); $salePrice = $facade->doIncludeTaxesToPrice($product, $salePrice); } $priceSuffix = $this->ecommerceFacade->getPriceSuffix($product); $salePrice = $this->getFormattedPrice($salePrice); $vars['salePrice'] = $salePrice.$priceSuffix; if ($this->_isDifferentPrices($regularPrice, $salePrice)) { $vars['price'] = $this->getFormattedPrice($regularPrice); } if (!$salePrice) { $regularPrice = $this->getFormattedPrice($regularPrice); $vars['salePrice'] = $regularPrice.$priceSuffix; } $content = $this->fetch( 'price_role_width_sale.phtml', $vars ); return $content; } // end _fetchSimpleBothRegularSalePrice private function _isDifferentPrices($regularPrice, $salePrice) { return $salePrice && $regularPrice != $salePrice; } // end _isDifferentPrices private function _isOneHundredPercentDiscountEnabled() { if ($this->isRegisteredUser()) { return $this->getAmountOfDiscountOrMarkUp() >= 100 && $this->isPercentDiscountType() && $this->isDiscountTypeEnabled(); } return false; } // end _isOneHundredPercentDiscountEnabled private function _isDisplayDefaultPriceForCustomerSavingsFilter($product) { $productPrice = $this->getPrice($product); $emptyPriceSymbol = $this->ecommerceFacade->getEmptyPriceSymbol(); return $productPrice && !$this->_isDefaultCurrencyActive() && $this->isRegisteredUser() && $productPrice !== $emptyPriceSymbol; } // end _isDisplayDefaultPriceForCustomerSavingsFilter private function _hasSalePriceForUserRole($product) { if (!$this->isVariableTypeProduct($product)) { $salePrice = $this->getSalePrice($product); return (bool) $salePrice; } } // end _hasSalePriceForUserRole private function _isDefaultCurrencyActive() { $defaultCurrency = WooCommerceFacade::getDefaultCurrencyCode(); $activeCurrency = WooCommerceFacade::getBaseCurrencyCode(); return $defaultCurrency == $activeCurrency; } // end _isDefaultCurrencyActive private function _fetchUserRolePrice($product) { $price = $this->getPrice($product); $formatPrice = $this->getFormattedPrice($price); $typePriceUser = WooUserRolePricesFrontendFestiPlugin::TYPE_PRICE_USER; return $this->fetchPrice($formatPrice, $typePriceUser); } // end _fetchUserRolePrice private function _fetchPriceAndSalePriceForUserRole($product) { $price = $this->getPrice($product); $salePrice = $this->getSalePrice($product); $facade = $this->ecommerceFacade; if ($this->isIncludingTaxesToPrice()) { $price = $facade->doIncludeTaxesToPrice($product, $price); $salePrice = $facade->doIncludeTaxesToPrice($product, $salePrice); } $vars = array( 'price' => $this->getFormattedPrice($price), 'salePrice' => $this->getFormattedPrice($salePrice) ); $content = $this->fetch( 'price_role_width_sale.phtml', $vars ); return $content; } // end _fetchPriceAndSalePriceForUserRole public function getFormattedPrice($price) { return wc_price($price); } // end getFormattedPrice public function isProductParentMainProduct($product) { $idParent = $this->ecommerceFacade->getProductParentID($product); if (!$idParent) { return false; } return $idParent == $this->mainProductOnPage; } // end isProductParentMainProduct public function getMainProductOnPage() { return $this->mainProductOnPage; } // end getMainProductOnPage public function removeFilter($hook, $methodName, $priority = 10) { if (!is_array($methodName)) { $methodName = array(&$this, $methodName); } remove_filter($hook, $methodName, $priority); } // end removeFilter public function onReplaceAllPriceToTextInSomeProductFilter($price, $product) { return WooUserRoleModule::get('HidePrice') ->onReplaceAllPriceToTextInSomeProductFilter($price, $product); } // end onReplaceAllPriceToTextInSomeProductFilter public function isProductPage() { return is_product(); } // end isProductPage public function onRemoveAddToCartButtonInSomeProductsFilter( $button, $product ) { return WooUserRoleModule::get('HidePrice') ->onRemoveAddToCartButtonInSomeProductsFilter($button, $product); } // end onRemoveAddToCartButtonInSomeProductsFilter public function onReplaceAllPriceToTextInAllProductFilter() { return $this->fetchContentInsteadOfPrices(); } //end onReplaceAllPriceToTextInAllProductFilter public function fetchContentInsteadOfPrices() { $vars = array( 'text' => $this->textInsteadPrices ); return $this->fetch('custom_text.phtml', $vars); } // end fetchContentInsteadOfPrices public function removeGroupedAddToCartLinkAction() { $vars = array( 'settings' => $this->getSettings(), ); echo $this->fetch('hide_grouped_add_to_cart_buttons.phtml', $vars); } // end removeGroupedAddToCartLinkAction public function removeVariableAddToCartLinkAction() { $vars = array( 'settings' => $this->getSettings(), ); echo $this->fetch('hide_variable_add_to_cart_buttons.phtml', $vars); } // end removeVariableAddToCartLinkAction public function onRemoveAllAddToCartButtonFilter($button, $product) { if ($this->_hasAddToCartButtonText($product)) { $settings = $this->getSettings(); return $settings['textForNonRegisteredUsers']; } return $button; } // end onRemoveAddToCartButtonFilter private function _hasAddToCartButtonText($product) { $facade = &$this->ecommerceFacade; return $facade->isProductPurchasableAndInStock($product); } // _hasAddToCartButtonText public function isAddToCartButtonHiddenAndProductPurchasable($product) { $settings = $this->getSettings(); $facade = &$this->ecommerceFacade; return array_key_exists('textForNonRegisteredUsers', $settings) && $facade->isProductPurchasableAndInStock($product); } // end isAddToCartButtonHiddenAndProductPurchasable public function getTemplatePath($fileName) { return $this->pluginTemplatePath.'frontend/'.$fileName; } // end getTemplatePath public function getPluginJsUrl($fileName, $customUrl = false) { if ($customUrl) { return $customUrl.$fileName; } return $this->pluginJsUrl.'frontend/'.$fileName; } // end getPluginJsUrl public function getPluginCssUrl($fileName, $customUrl = false) { if ($customUrl) { return $customUrl.$fileName; } return $this->pluginUrl.$fileName; } // end getPluginCssUrl public function onInitJsAction() { $this->onEnqueueJsFileAction('jquery'); $this->onEnqueueJsFileAction( 'festi-user-role-prices-general', 'general.js', 'jquery', $this->version ); } // end onInitJsAction public function onInitCssAction() { $this->addActionListener( 'wp_head', 'appendCssToHeaderForCustomerSavingsCustomize' ); $this->onEnqueueCssFileAction( 'festi-user-role-prices-styles', 'static/styles/frontend/style.css', array(), $this->version ); } // end onInitCssAction public function appendCssToHeaderForCustomerSavingsCustomize() { if (!$this->hasOptionInSettings('showCustomerSavings')) { return false; } $vars = array( 'settings' => $this->getSettings(), ); echo $this->fetch('customer_savings_customize_style.phtml', $vars); } // end appendCssToHeaderForPriceCustomize public function hasOptionInSettings($option) { $settings = $this->getSettings(); return array_key_exists($option, $settings); } // end hasOptionInSettings public function isWoocommerceMultiLanguageActive() { $pluginPath = 'woocommerce-multilingual/wpml-woocommerce.php'; return $this->isPluginActive($pluginPath); } // end isWoocommerceMultiLanguageActive public function onDisplayOnlyProductStockStatusAction() { $vars = array( 'settings' => $this->getSettings(), ); echo $this->fetch('stock_status_for_simple_type_product.phtml', $vars); } // end onDisplayOnlyProductStockStatusAction private function _setPrepareDisplayUserRoleTaxes() { $ecommerceFacade = $this->ecommerceFacade; $settings = $this->getTaxByUserRoleOptions(); if (!$settings) { return false; } $taxDisplayType = $settings['taxType']; if ($taxDisplayType == static::FESTI_DEFAULT_TAX_KEY) { return false; } $engineFacade = EngineFacade::getInstance(); $shopHookName = $ecommerceFacade->getHookNameForDisplayPicesTax(); $cartHookName = $ecommerceFacade->getHookNameForDisplayPicesTax('cart'); $excludingTax = WooCommerceFacade::FESTI_DISPLAY_PRICES_EXCLUDING_TAX; switch ($taxDisplayType) { case static::FESTI_EXCLUDE_ALL_TAX_KEY: $engineFacade->updateOption( $shopHookName, $excludingTax ); $engineFacade->updateOption( $cartHookName, $excludingTax ); break; case static::FESTI_EXCLUDE_TAX_IN_SHOP_KEY: $engineFacade->updateOption( $shopHookName, $excludingTax ); break; case static::FESTI_EXCLUDE_TAX_IN_CART_AND_CHECKOUT_KEY: $engineFacade->updateOption( $cartHookName, $excludingTax ); break; } } // end _setPrepareDisplayUserRoleTaxes private function _setCartItemsCount() { $name = ModulesSwitchListener::QUANTITY_DISCOUNT_PLUGIN; if ($this->isModuleExist($name)) { $facade = WooCommerceCartFacade::getInstance(); $count = $facade->getCartContentsCount(); $pluginName = $name.'Plugin'; $file = PRICE_BY_ROLE_EXTENSIONS_DIR. $name.DIRECTORY_SEPARATOR.$pluginName.'.php'; require_once($file); $pluginName::$cartItemsCount = $count; } } // end _setCartItemsCount }