| @@ -39,24 +39,14 @@ | ||
| 39 | 39 | * @return string |
| 40 | 40 | */ |
| 41 | 41 | public function formatPrice( $priceHtml, $product ) { |
| 42 | 42 | |
| 43 | - $product_id = $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id(); | |
| 44 | - | |
| 45 | 43 | $formatCondition = $this->settings->get( 'tiered_price_at_product_page', |
| 46 | - 'no' ) === 'yes' || get_queried_object_id() != $product_id; | |
| 44 | + 'no' ) === 'yes' || get_queried_object_id() != $product->get_id(); | |
| 47 | 45 | |
| 48 | 46 | if ( $formatCondition ) { |
| 49 | 47 | $displayPriceType = $this->getDisplayType(); |
| 50 | 48 | |
| 51 | - if ( $product instanceof WC_Product_Variable && $this->useForVariable() === 'yes' ) { | |
| 52 | - $price = $this->formatPriceForVariableProduct( $product ); | |
| 53 | - | |
| 54 | - if ( $price ) { | |
| 55 | - return $price; | |
| 56 | - } | |
| 57 | - } | |
| 58 | - | |
| 59 | 49 | if ( in_array( $product->get_type(), [ 'simple', 'variation' ] ) ) { |
| 60 | 50 | $rules = PriceManager::getPriceRules( $product->get_id() ); |
| 61 | 51 | |
| 62 | 52 | if ( ! empty( $rules ) ) { |
| @@ -67,9 +57,14 @@ | ||
| 67 | 57 | } |
| 68 | 58 | } |
| 69 | 59 | } |
| 70 | 60 | |
| 71 | - | |
| 61 | + if ( $product instanceof WC_Product_Variable && $this->useForVariable() === 'yes' ) { | |
| 62 | + $price = $this->formatPriceForVariableProduct( $product ); | |
| 63 | + if ( $price ) { | |
| 64 | + return $price; | |
| 65 | + } | |
| 66 | + } | |
| 72 | 67 | } |
| 73 | 68 | |
| 74 | 69 | return $priceHtml; |
| 75 | 70 | } |
| @@ -89,16 +84,15 @@ | ||
| 89 | 84 | $minPrices = []; |
| 90 | 85 | |
| 91 | 86 | foreach ( $product->get_available_variations() as $variation ) { |
| 92 | 87 | $rules = PriceManager::getPriceRules( $variation['variation_id'] ); |
| 88 | + | |
| 93 | 89 | if ( ! empty( $rules ) ) { |
| 94 | 90 | |
| 95 | - $minPrices[] = $this->getLowestPrice( $rules, wc_get_product( $variation['variation_id'] ), false ); | |
| 91 | + $minPrices[] = $this->getLowestPrice( $rules, $product, false ); | |
| 96 | 92 | } |
| 97 | - | |
| 98 | 93 | } |
| 99 | 94 | |
| 100 | - | |
| 101 | 95 | if ( ! empty( $minPrices ) ) { |
| 102 | 96 | if ( $this->getDisplayType() === 'range' ) { |
| 103 | 97 | return wc_price( min( $minPrices ) ) . ' - ' . wc_price( $maxPrice ); |
| 104 | 98 | } else { |
| @@ -120,20 +114,28 @@ | ||
| 120 | 114 | protected function getRange( $rules, $product ) { |
| 121 | 115 | |
| 122 | 116 | $lowest = array_pop( $rules ); |
| 123 | 117 | |
| 124 | - $highest_html = wc_price( PriceManager::getPriceWithTaxes( $product->get_price(), $product ) ); | |
| 118 | + $highest_html = wc_price( wc_get_price_to_display( $product, [ | |
| 119 | + 'price' => $product->get_price(), | |
| 120 | + ] ) ); | |
| 125 | 121 | |
| 126 | 122 | if ( PriceManager::getPricingType( $product->get_id() ) === 'percentage' ) { |
| 127 | 123 | |
| 128 | - $price = PriceManager::getPriceByPercentDiscount( $product->get_price(), $lowest ); | |
| 124 | + $lowest_html = wc_price( | |
| 125 | + wc_get_price_to_display( $product, [ | |
| 126 | + 'price' => PriceManager::getPriceByPercentDiscount( $product->get_price(), $lowest ), | |
| 127 | + ] ) | |
| 128 | + ); | |
| 129 | 129 | |
| 130 | - $lowest_html = wc_price( PriceManager::getPriceWithTaxes( $price, $product ) ); | |
| 131 | - | |
| 132 | 130 | return $lowest_html . ' - ' . $highest_html; |
| 133 | 131 | } |
| 134 | 132 | |
| 135 | - $lowest_html = wc_price( PriceManager::getPriceWithTaxes( $lowest, $product ) ); | |
| 133 | + $lowest_html = wc_price( | |
| 134 | + wc_get_price_to_display( $product, [ | |
| 135 | + 'price' => $lowest, | |
| 136 | + ] ) | |
| 137 | + ); | |
| 136 | 138 | |
| 137 | 139 | return $lowest_html . ' - ' . $highest_html; |
| 138 | 140 | } |
| 139 | 141 | |
| @@ -155,12 +157,16 @@ | ||
| 155 | 157 | $lowest = array_pop( $rules ); |
| 156 | 158 | } |
| 157 | 159 | |
| 158 | 160 | if ( ! $html ) { |
| 159 | - return PriceManager::getPriceWithTaxes( $lowest, $product, 'shop' ); | |
| 161 | + return wc_get_price_to_display( $product, [ | |
| 162 | + 'price' => $lowest | |
| 163 | + ] ); | |
| 160 | 164 | } |
| 161 | 165 | |
| 162 | - return $this->getLowestPrefix() . ' ' . wc_price( PriceManager::getPriceWithTaxes( $lowest, $product ) ); | |
| 166 | + return $this->getLowestPrefix() . ' ' . wc_price( wc_get_price_to_display( $product, [ | |
| 167 | + 'price' => $lowest | |
| 168 | + ] ) ); | |
| 163 | 169 | } |
| 164 | 170 | |
| 165 | 171 | public function getLowestPrefix() { |
| 166 | 172 | return $this->settings->get( 'lowest_prefix', __( 'From', 'tier-pricing-table' ) ); |