Skip to content

minicart offers for woocommerce#101

Merged
jm-extend merged 4 commits intomasterfrom
SOL-1450-minicart-offers
Mar 25, 2026
Merged

minicart offers for woocommerce#101
jm-extend merged 4 commits intomasterfrom
SOL-1450-minicart-offers

Conversation

@jm-extend
Copy link
Copy Markdown
Collaborator

@jm-extend jm-extend commented Mar 23, 2026

minicart offers support added

Summary by CodeRabbit

  • New Features
    • Added warranty protection offers to the shopping cart mini-cart view, allowing customers to add extended protection plans directly from their cart preview without navigating to the full checkout page.

minicart offers support added
@jm-extend jm-extend self-assigned this Mar 23, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f358ea5c-091b-478f-ba16-9a8586981e84

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This pull request adds mini-cart offer functionality to the HelloExtend Protection plugin. A new public method minicart_offers() was introduced to the cart offer class that builds cart contents data from WooCommerce items and enqueues a dedicated integration script. A WordPress hook was registered to trigger mini-cart offer initialization. A new script registration for helloextend_minicart_integration_script was added, along with a new JavaScript file (helloextend-minicart-offers.js) that renders warranty offers within individual mini-cart line items using the Extend API and handles plan addition and cart updates.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@helloextend-protection/includes/class-helloextend-protection-cart-offer.php`:
- Around line 287-295: The loop in class HelloExtend_Protection_Cart_Offer
(method where $categories is iterated) uses the wrong variable name: it checks
$ignored instead of the lookup table $ignored_set, so ignored categories never
get skipped; update the conditional inside the foreach to test
isset($ignored_set[(int)($cat ?? 0)]) and invert the logic so you only break
when the category is not in $ignored_set (i.e., if
(!isset($ignored_set[(int)($cat ?? 0)])) { $category = $term ?? 'Uncategorized';
break; }), ensuring you reference $ignored_set rather than $ignored.
- Around line 267-317: Initialize $cart_contents as an empty array before the
foreach over WC()->cart->get_cart(), and inside the loop skip any
warranty/Extend rows by checking for the extend marker (e.g., if ( isset(
$cart_item['extendData'] ) ) continue; ), so they are not serialized into
$cart_contents; also fix the variable-name bug by using $ignored_set (not
$ignored) when checking ignored categories in the foreach that assigns
$category.
- Around line 249-253: minicart_offers() and cart_offers() both call
wp_localize_script with the same global name ExtendCartIntegration, causing one
payload to overwrite the other; change the localization keys so they are unique
(e.g., use ExtendMinicartIntegration for minicart_offers() and keep
ExtendCartIntegration for cart_offers()), update the corresponding
wp_localize_script calls and any client-side references to those globals, and
ensure the script handle passed to wp_localize_script still matches the enqueued
script in both functions.
- Around line 297-305: minicart_offers() is passing price_raw as WooCommerce's
decimal string while after_cart_item_name() expects a cents integer (converted
via (int) floatval($price * 100)), causing mini-cart prices to be 100x too low;
update minicart_offers() to normalize price_raw to cents by converting the
product price (e.g., $product->get_price()) to an integer cents value using the
same logic as after_cart_item_name() before including it in the $item array so
Extend.buttons.renderSimpleOffer() receives a cents integer; ensure you update
the 'price_raw' assignment in the array built in minicart_offers() and keep
'price_formatted' as the human-readable wc_price() string.

In `@helloextend-protection/js/helloextend-minicart-offers.js`:
- Around line 20-29: The code pulls item fields from the stale global
ExtendCartIntegration.cart_contents using cart_item_key inside
initMiniCartOffers instead of using the fresh cart payload passed from
getCart(); update initMiniCartOffers (and other spots using
ExtendCartIntegration.cart_contents such as the blocks around the
sku/name/price/quantity/category and the occurrences noted at the other
locations) to read item metadata from the incoming cart parameter (e.g.,
cart.items or cart.contents) for the given cart_item_key, falling back to
ExtendCartIntegration.cart_contents only if the cart param is absent; ensure
getCart()'s fresh cart is actually consumed so AJAX fragment updates produce
correct item data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 788c5dad-77fa-42c8-9ba6-61ad90712452

📥 Commits

Reviewing files that changed from the base of the PR and between 4f04e29 and 6165d64.

📒 Files selected for processing (3)
  • helloextend-protection/includes/class-helloextend-protection-cart-offer.php
  • helloextend-protection/includes/class-helloextend-protection.php
  • helloextend-protection/js/helloextend-minicart-offers.js

Comment thread helloextend-protection/js/helloextend-minicart-offers.js
Johnathnnault
Johnathnnault previously approved these changes Mar 23, 2026
- variable $cart_Contents was not properly initialized
- cart normalization did not exist in the minicart.
@jm-extend jm-extend merged commit ac51085 into master Mar 25, 2026
6 checks passed
@jm-extend jm-extend deleted the SOL-1450-minicart-offers branch March 25, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants