Removing Prices for Bundled Product Options in Magento
When working with bundled products in Magento, you might encounter situations where you want to remove the prices displayed alongside the options on the shopping cart page and during checkout. This is especially useful when offering customizable bundles or when the final price depends on customer input.
Understanding the Problem
By default, Magento displays the price for each option within a bundled product. However, there are cases where this information should not be visible to the customer. For example, if you offer a “Create Your Own Gift Box” feature and the box contents depend entirely on the user’s selection, showing prices for individual items can be confusing.
The current shopping cart view displays prices for each option in the bundle:
Step-by-Step Solution
To remove these prices, you’ll need to override a core template file and modify some JavaScript functionality. Here’s how:
1. Override the cart/item/default.phtml File
First, create a new file named item.phtml in your custom theme under this path: app/design/frontend/{your_theme_package}/{your_theme_name}/Magento_Checkout/templates/cart
The contents of this file should be identical to the original file located at vendor/magento/module-checkout/view/frontend/templates/cart/item/default.phtml, but you’ll need to make a small modification.
2. Modify the Price Display Logic
In your new item.phtml file, look for this line around line 16:
<?= /* @escapeNotVerified */ $block->getProductPrice($item) ?>
Replace it with an empty string or any other placeholder text you prefer:
<!-- Custom Price Placeholder -->
This will replace the default price display with your custom content.
3. Update the JavaScript Functionality
Next, we need to update the require-js-config.js file in your theme’s main layout directory (app/design/frontend/{your_theme_package}/{your_theme_name}/Magento_Checkout/layout). Add or modify the following config:
config: {
mixins: {
'Magento_Catalog/js/catalog-add-to-cart': {
'Magento_Checkout/js/view/checkout-bundle-item': function (target) {
return target.extend({
isPriceVisible: function () {
// Always return false to hide the price
return false;
},
});
}
},
},
},
This mixin extends the checkout-bundle-item JavaScript file and overrides the isPriceVisible method, forcing it to always return false.
Testing Your Changes
After making these modifications, clear your cache using:
php bin/magento cache:clean
Then, test your changes by adding a bundled product to your cart. You should now see that the prices for individual options have been removed.
Conclusion
Removing prices for bundled options in Magento requires careful modification of both the template files and the JavaScript functionality involved in rendering the shopping cart and checkout pages. By following this guide, you can effectively hide these prices without affecting the overall functionality of your store’s bundle products.
Remember to always test changes thoroughly before deploying them to a production environment. If you encounter any issues or need further assistance with Magento development, feel free to contact us at https://laravelcompany.com.
Happy coding!
