getProductMeta($post, $field['args']['old-price'], true); $newPrice = (float)$this->getProductMeta($post, $field['args']['new-price'], true); if ( empty($oldPrice) || empty($newPrice) || $newPrice > $oldPrice ) { return ''; } $discountValue = ($oldPrice - $newPrice) * 100 / $oldPrice; if ((isset($field['args']['show-decimal']) && 'true' === $field['args']['show-decimal'])) { $discountValue = $this->round($discountValue, $field); $result = number_format($discountValue, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()); } else { $discountValue = $this->round($discountValue, $field); if (false !== strpos((string)$discountValue, '.')) { $parts = explode('.', $discountValue); $result = $parts[0]; } else { $result = $discountValue; } } return !empty($result) ? $this->getValueWithCurrency($result, $field) : ''; } }