PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / CustomColumns / Columns / SavingPerItemColumn.php

SavingPerItemColumn.php in Tiered Pricing Table for WooCommerce 7.1.4, at src/Addons/CustomColumns/Columns/SavingPerItemColumn.php

56 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\CustomColumns\Columns;
2
3 use TierPricingTable\PricingRule;
4
5 class SavingPerItemColumn extends AbstractCustomColumn {
6
7 const TYPE = 'saving_per_item';
8
9 public function getType(): string {
10 return self::TYPE;
11 }
12
13 public function getDataType(): string {
14 return 'price';
15 }
16
17 protected function _getSingleRowValue( PricingRule $pricingRule, $currentTierQuantity = null ): string {
18 $product = wc_get_product( $pricingRule->getProductId() );
19
20 if ( $currentTierQuantity && $product ) {
21 $tierPrice = $pricingRule->getTierPrice( $currentTierQuantity, false );
22 $regularPrice = (float) $product->get_price();
23
24 if ( $tierPrice && $regularPrice && $regularPrice > $tierPrice ) {
25 $saving = $regularPrice - $tierPrice;
26 $priceHtml = wc_price( wc_get_price_to_display( $product, array(
27 'price' => $saving,
28 ) ) );
29
30 $unitName = get_post_meta( $product->get_id(), '_tiered_pricing_base_unit_name', true );
31 $unitLabel = '';
32
33 if ( ! empty( $unitName['singular'] ) ) {
34 $unitLabel = $unitName['singular'];
35 } else {
36 $quantity_measurement = \TierPricingTable\Core\ServiceContainer::getInstance()->getSettings()->get( 'table_quantity_measurement', array(
37 'singular' => '',
38 'plural' => '',
39 ) );
40 if ( ! empty( $quantity_measurement['singular'] ) ) {
41 $unitLabel = $quantity_measurement['singular'];
42 }
43 }
44
45 if ( $unitLabel ) {
46 $priceHtml .= '<span> / ' . $unitLabel . '</span>';
47 }
48
49 return $priceHtml;
50 }
51 }
52
53 return '-';
54 }
55 }
56