← All changes
|
app/Hooks/Handlers/BlockEditors/Buttons/AddToCartButtonBlockEditor.php
+6
-1
1.3.21
→
1.6.5
View file →
| @@ -111,9 +111,14 @@ | ||
| 111 | 111 | return ''; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | ob_start(); |
| 115 | - (new ProductRenderer($product))->renderAddToCartButtonBlock($shortCodeAttribute); | |
| 115 | + // Pass the block's selected variant as the renderer's default variation | |
| 116 | + // so the button's data-cart-id (and stock/price) reflect that variant. | |
| 117 | + // Without this the renderer falls back to the product's first/default | |
| 118 | + // variant, and the button always adds the wrong variant to the cart. | |
| 119 | + (new ProductRenderer($product, ['default_variation_id' => $variant->id])) | |
| 120 | + ->renderAddToCartButtonBlock($shortCodeAttribute); | |
| 116 | 121 | return ob_get_clean(); |
| 117 | 122 | } |
| 118 | 123 | |
| 119 | 124 | } |