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:
@@ -485,7 +485,9 @@ class Informatiq_SP_Admin {
|
|||||||
value="<?php echo esc_attr( $value ); ?>" min="0" max="100" step="0.01" class="small-text">
|
value="<?php echo esc_attr( $value ); ?>" min="0" max="100" step="0.01" class="small-text">
|
||||||
<span>%</span>
|
<span>%</span>
|
||||||
<p class="description">
|
<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>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@@ -621,7 +623,9 @@ class Informatiq_SP_Admin {
|
|||||||
<th><?php esc_html_e( 'Product', 'informatiq-smart-pricing' ); ?></th>
|
<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( 'Your Price', 'informatiq-smart-pricing' ); ?></th>
|
||||||
<th><?php esc_html_e( 'Suggested', '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' ); ?>">
|
<th title="<?php esc_attr_e( 'Predicted change in impressions', 'informatiq-smart-pricing' ); ?>">
|
||||||
<?php esc_html_e( 'Impr.', 'informatiq-smart-pricing' ); ?>
|
<?php esc_html_e( 'Impr.', 'informatiq-smart-pricing' ); ?>
|
||||||
</th>
|
</th>
|
||||||
@@ -897,12 +901,32 @@ class Informatiq_SP_Admin {
|
|||||||
// Calculate potential gain and determine if update is beneficial.
|
// Calculate potential gain and determine if update is beneficial.
|
||||||
$suggested_price = $insight['suggested_price'] ?? null;
|
$suggested_price = $insight['suggested_price'] ?? null;
|
||||||
$potential_gain = null;
|
$potential_gain = null;
|
||||||
|
$percent_diff = null;
|
||||||
$should_update = false;
|
$should_update = false;
|
||||||
|
|
||||||
|
// Get minimum margin setting.
|
||||||
|
$min_margin = (float) get_option( 'informatiq_sp_minimum_margin', 10 );
|
||||||
|
|
||||||
if ( $suggested_price && $local_price_incl_tax ) {
|
if ( $suggested_price && $local_price_incl_tax ) {
|
||||||
$potential_gain = round( $suggested_price - $local_price_incl_tax, 2 );
|
$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(
|
$comparison[] = array(
|
||||||
@@ -913,6 +937,7 @@ class Informatiq_SP_Admin {
|
|||||||
'price_type' => $price_type,
|
'price_type' => $price_type,
|
||||||
'google_price' => $insight['google_price'] ?? null,
|
'google_price' => $insight['google_price'] ?? null,
|
||||||
'suggested_price' => $suggested_price,
|
'suggested_price' => $suggested_price,
|
||||||
|
'percent_diff' => $percent_diff,
|
||||||
'potential_gain' => $potential_gain,
|
'potential_gain' => $potential_gain,
|
||||||
'predicted_impressions_change' => $insight['predicted_impressions_change'] ?? null,
|
'predicted_impressions_change' => $insight['predicted_impressions_change'] ?? null,
|
||||||
'predicted_clicks_change' => $insight['predicted_clicks_change'] ?? null,
|
'predicted_clicks_change' => $insight['predicted_clicks_change'] ?? null,
|
||||||
|
|||||||
@@ -307,19 +307,19 @@
|
|||||||
var suggestedPrice = product.suggested_price ? data.currency + parseFloat(product.suggested_price).toFixed(2) : '-';
|
var suggestedPrice = product.suggested_price ? data.currency + parseFloat(product.suggested_price).toFixed(2) : '-';
|
||||||
var priceLabel = product.price_type === 'sale' ? ' <small>(sale)</small>' : '';
|
var priceLabel = product.price_type === 'sale' ? ' <small>(sale)</small>' : '';
|
||||||
|
|
||||||
// Gain/loss styling
|
// Percentage difference styling
|
||||||
var gainHtml = '-';
|
var percentDiffHtml = '-';
|
||||||
var gainStyle = '';
|
var percentDiffStyle = '';
|
||||||
if (product.potential_gain !== null) {
|
if (product.percent_diff !== null) {
|
||||||
var gain = parseFloat(product.potential_gain);
|
var pct = parseFloat(product.percent_diff);
|
||||||
if (gain > 0) {
|
if (pct > 0) {
|
||||||
gainHtml = '+' + data.currency + gain.toFixed(2);
|
percentDiffHtml = '+' + pct.toFixed(1) + '%';
|
||||||
gainStyle = 'color: #00a32a; font-weight: bold;';
|
percentDiffStyle = 'color: #00a32a; font-weight: bold;';
|
||||||
} else if (gain < 0) {
|
} else if (pct < 0) {
|
||||||
gainHtml = '-' + data.currency + Math.abs(gain).toFixed(2);
|
percentDiffHtml = pct.toFixed(1) + '%';
|
||||||
gainStyle = 'color: #d63638;';
|
percentDiffStyle = 'color: #d63638;';
|
||||||
} else {
|
} else {
|
||||||
gainHtml = data.currency + '0.00';
|
percentDiffHtml = '0%';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@
|
|||||||
html += '<td><a href="post.php?post=' + product.id + '&action=edit" title="SKU: ' + product.sku + '">' + self.truncate(product.name, 40) + '</a></td>';
|
html += '<td><a href="post.php?post=' + product.id + '&action=edit" title="SKU: ' + product.sku + '">' + self.truncate(product.name, 40) + '</a></td>';
|
||||||
html += '<td>' + localPrice + priceLabel + '</td>';
|
html += '<td>' + localPrice + priceLabel + '</td>';
|
||||||
html += '<td>' + suggestedPrice + '</td>';
|
html += '<td>' + suggestedPrice + '</td>';
|
||||||
html += '<td style="' + gainStyle + '">' + gainHtml + '</td>';
|
html += '<td style="' + percentDiffStyle + '">' + percentDiffHtml + '</td>';
|
||||||
html += '<td style="' + imprStyle + '">' + imprChange + '</td>';
|
html += '<td style="' + imprStyle + '">' + imprChange + '</td>';
|
||||||
html += '<td style="' + clickStyle + '">' + clickChange + '</td>';
|
html += '<td style="' + clickStyle + '">' + clickChange + '</td>';
|
||||||
html += '<td style="' + convStyle + '">' + convChange + '</td>';
|
html += '<td style="' + convStyle + '">' + convChange + '</td>';
|
||||||
|
|||||||
Reference in New Issue
Block a user