diff --git a/admin/class-informatiq-sp-admin.php b/admin/class-informatiq-sp-admin.php
index 005777de..ce31df71 100644
--- a/admin/class-informatiq-sp-admin.php
+++ b/admin/class-informatiq-sp-admin.php
@@ -485,7 +485,9 @@ class Informatiq_SP_Admin {
value="" min="0" max="100" step="0.01" class="small-text">
%
-
+
+
+
|
|
- |
+
+
+ |
|
@@ -897,12 +901,32 @@ class Informatiq_SP_Admin {
// Calculate potential gain and determine if update is beneficial.
$suggested_price = $insight['suggested_price'] ?? null;
$potential_gain = null;
+ $percent_diff = null;
$should_update = false;
+ // Get minimum margin setting.
+ $min_margin = (float) get_option( 'informatiq_sp_minimum_margin', 10 );
+
if ( $suggested_price && $local_price_incl_tax ) {
$potential_gain = round( $suggested_price - $local_price_incl_tax, 2 );
- // Suggest update if Google recommends a different price.
- $should_update = abs( $potential_gain ) > 0.05;
+
+ // Calculate percentage difference.
+ $percent_diff = round( ( ( $suggested_price - $local_price_incl_tax ) / $local_price_incl_tax ) * 100, 1 );
+
+ // Calculate minimum allowed price (current price - margin%).
+ $min_allowed_price = $local_price_incl_tax * ( 1 - ( $min_margin / 100 ) );
+
+ // Only suggest update if:
+ // 1. Google recommends a different price (more than 0.05 diff)
+ // 2. Suggested price is above our minimum allowed price
+ $should_update = abs( $potential_gain ) > 0.05 && $suggested_price >= $min_allowed_price;
+
+ // If suggested is below minimum, cap it.
+ if ( $suggested_price < $min_allowed_price ) {
+ $suggested_price = round( $min_allowed_price, 2 );
+ $potential_gain = round( $suggested_price - $local_price_incl_tax, 2 );
+ $percent_diff = round( ( ( $suggested_price - $local_price_incl_tax ) / $local_price_incl_tax ) * 100, 1 );
+ }
}
$comparison[] = array(
@@ -913,6 +937,7 @@ class Informatiq_SP_Admin {
'price_type' => $price_type,
'google_price' => $insight['google_price'] ?? null,
'suggested_price' => $suggested_price,
+ 'percent_diff' => $percent_diff,
'potential_gain' => $potential_gain,
'predicted_impressions_change' => $insight['predicted_impressions_change'] ?? null,
'predicted_clicks_change' => $insight['predicted_clicks_change'] ?? null,
diff --git a/assets/js/admin.js b/assets/js/admin.js
index fe8d5e33..488aa933 100644
--- a/assets/js/admin.js
+++ b/assets/js/admin.js
@@ -307,19 +307,19 @@
var suggestedPrice = product.suggested_price ? data.currency + parseFloat(product.suggested_price).toFixed(2) : '-';
var priceLabel = product.price_type === 'sale' ? ' (sale)' : '';
- // Gain/loss styling
- var gainHtml = '-';
- var gainStyle = '';
- if (product.potential_gain !== null) {
- var gain = parseFloat(product.potential_gain);
- if (gain > 0) {
- gainHtml = '+' + data.currency + gain.toFixed(2);
- gainStyle = 'color: #00a32a; font-weight: bold;';
- } else if (gain < 0) {
- gainHtml = '-' + data.currency + Math.abs(gain).toFixed(2);
- gainStyle = 'color: #d63638;';
+ // Percentage difference styling
+ var percentDiffHtml = '-';
+ var percentDiffStyle = '';
+ if (product.percent_diff !== null) {
+ var pct = parseFloat(product.percent_diff);
+ if (pct > 0) {
+ percentDiffHtml = '+' + pct.toFixed(1) + '%';
+ percentDiffStyle = 'color: #00a32a; font-weight: bold;';
+ } else if (pct < 0) {
+ percentDiffHtml = pct.toFixed(1) + '%';
+ percentDiffStyle = 'color: #d63638;';
} else {
- gainHtml = data.currency + '0.00';
+ percentDiffHtml = '0%';
}
}
@@ -351,7 +351,7 @@
html += '' + self.truncate(product.name, 40) + ' | ';
html += '' + localPrice + priceLabel + ' | ';
html += '' + suggestedPrice + ' | ';
- html += '' + gainHtml + ' | ';
+ html += '' + percentDiffHtml + ' | ';
html += '' + imprChange + ' | ';
html += '' + clickChange + ' | ';
html += '' + convChange + ' | ';