Show Update button for all products with insight data
- Removed margin check from manual update display - Update button now shows for ALL products that have Google price suggestions - Margin setting only applies to automatic updates (protection against auto price drops) - Full manual control: user decides whether to accept each suggestion Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -902,31 +902,12 @@ class Informatiq_SP_Admin {
|
|||||||
$suggested_price = $insight['suggested_price'] ?? null;
|
$suggested_price = $insight['suggested_price'] ?? null;
|
||||||
$potential_gain = null;
|
$potential_gain = null;
|
||||||
$percent_diff = 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 ) {
|
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 );
|
||||||
|
|
||||||
// Calculate percentage difference.
|
// Calculate percentage difference.
|
||||||
$percent_diff = round( ( ( $suggested_price - $local_price_incl_tax ) / $local_price_incl_tax ) * 100, 1 );
|
$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(
|
||||||
@@ -943,7 +924,6 @@ class Informatiq_SP_Admin {
|
|||||||
'predicted_clicks_change' => $insight['predicted_clicks_change'] ?? null,
|
'predicted_clicks_change' => $insight['predicted_clicks_change'] ?? null,
|
||||||
'predicted_conversions_change' => $insight['predicted_conversions_change'] ?? null,
|
'predicted_conversions_change' => $insight['predicted_conversions_change'] ?? null,
|
||||||
'has_insight' => ! empty( $insight ),
|
'has_insight' => ! empty( $insight ),
|
||||||
'should_update' => $should_update,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -338,13 +338,13 @@
|
|||||||
var clickStyle = product.predicted_clicks_change > 0 ? 'color:#00a32a;' : (product.predicted_clicks_change < 0 ? 'color:#d63638;' : '');
|
var clickStyle = product.predicted_clicks_change > 0 ? 'color:#00a32a;' : (product.predicted_clicks_change < 0 ? 'color:#d63638;' : '');
|
||||||
var convStyle = product.predicted_conversions_change > 0 ? 'color:#00a32a;' : (product.predicted_conversions_change < 0 ? 'color:#d63638;' : '');
|
var convStyle = product.predicted_conversions_change > 0 ? 'color:#00a32a;' : (product.predicted_conversions_change < 0 ? 'color:#d63638;' : '');
|
||||||
|
|
||||||
// Checkbox and action button
|
// Checkbox and action button - show for all products with insight data
|
||||||
var checkbox = product.has_insight && product.should_update
|
var checkbox = product.has_insight && product.suggested_price
|
||||||
? '<input type="checkbox" class="informatiq-sp-select-product" data-product-id="' + product.id + '" data-new-price="' + product.suggested_price + '">'
|
? '<input type="checkbox" class="informatiq-sp-select-product" data-product-id="' + product.id + '" data-new-price="' + product.suggested_price + '">'
|
||||||
: '';
|
: '';
|
||||||
var actionBtn = product.has_insight && product.should_update
|
var actionBtn = product.has_insight && product.suggested_price
|
||||||
? '<button type="button" class="button button-small informatiq-sp-update-single" data-product-id="' + product.id + '" data-new-price="' + product.suggested_price + '">Update</button>'
|
? '<button type="button" class="button button-small informatiq-sp-update-single" data-product-id="' + product.id + '" data-new-price="' + product.suggested_price + '">Update</button>'
|
||||||
: '-';
|
: (product.has_insight ? '<span style="color:#888;">No suggestion</span>' : '-');
|
||||||
|
|
||||||
html += '<tr>';
|
html += '<tr>';
|
||||||
html += '<td>' + checkbox + '</td>';
|
html += '<td>' + checkbox + '</td>';
|
||||||
|
|||||||
Reference in New Issue
Block a user