Add percentage diff column and price floor based on current price

Changes:
- Added "% Diff" column showing percentage difference between your price and suggested
- Changed minimum price logic: uses "Current Price - Margin%" instead of cost-based
- Updated settings description to explain the new logic
- Example: With 10% margin, €100 product won't be suggested below €90

This works better for stores without cost data - protects against excessive price drops.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 18:42:00 +01:00
parent b07810a88e
commit 12d96caf0c
2 changed files with 42 additions and 17 deletions

View File

@@ -485,7 +485,9 @@ class Informatiq_SP_Admin {
value="<?php echo esc_attr( $value ); ?>" min="0" max="100" step="0.01" class="small-text">
<span>%</span>
<p class="description">
<?php esc_html_e( 'Minimum profit margin to maintain. Prices will never go below (Cost + Margin%).', 'informatiq-smart-pricing' ); ?>
<?php esc_html_e( 'Maximum price reduction allowed. Suggested prices will never go below (Current Price - Margin%).', 'informatiq-smart-pricing' ); ?>
<br>
<em><?php esc_html_e( 'Example: With 10%, a €100 product will never be suggested below €90.', 'informatiq-smart-pricing' ); ?></em>
</p>
<?php
}
@@ -621,7 +623,9 @@ class Informatiq_SP_Admin {
<th><?php esc_html_e( 'Product', 'informatiq-smart-pricing' ); ?></th>
<th><?php esc_html_e( 'Your Price', 'informatiq-smart-pricing' ); ?></th>
<th><?php esc_html_e( 'Suggested', 'informatiq-smart-pricing' ); ?></th>
<th><?php esc_html_e( 'Gain/Loss', 'informatiq-smart-pricing' ); ?></th>
<th title="<?php esc_attr_e( 'Percentage difference from your price', 'informatiq-smart-pricing' ); ?>">
<?php esc_html_e( '% Diff', 'informatiq-smart-pricing' ); ?>
</th>
<th title="<?php esc_attr_e( 'Predicted change in impressions', 'informatiq-smart-pricing' ); ?>">
<?php esc_html_e( 'Impr.', 'informatiq-smart-pricing' ); ?>
</th>
@@ -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,