I have a custom shipping method. If I select that custom shipping method, I need to render the custom message below shipping method list. How can I do this?
Asked
Active
Viewed 2,061 times
1 Answers
1
Copy file from
vendor/magento/module-checkout/view/frontend/web/template/shipping.html
and paste into your theme as shown in the following path
app/design/frontend/namespace/theme/Magento_Checkout/web/template/shipping.html
Now find following table tag
<table class="table-checkout-shipping-method">
.
.
.
</table>
Add your message after this table as shown in following code
<table class="table-checkout-shipping-method">
.
.
.
</table>
<div class="custom-shipping-method-message" style="display: none;">This is custom shipping method message</div>
Now Add following jQuery code your page.
<script type="text/javascript">
require(["jquery"], function($) {
jQuery(document).ready(function(){
jQuery('body').on('click', '.table-checkout-shipping-method input[type="radio"]', function(){
var code = 'your_custom_shipping_method_code';
// you can check your custom shipping method code using inspect element
// you can see the code in the value of input type radio
if(jQuery(this).val() == code){
jQuery('.custom-shipping-method-message').show();
} else {
jQuery('.custom-shipping-method-message').hide();
}
});
});
}
</script>
Run the following command
php bin/magento setup:static-content:deploy -f
Dinesh Yadav
- 6,447
- 2
- 23
- 50
-
script is not run . I have to console.log('msg'); also but no any message in console i am using 2.3.2v – HaFiz Umer Oct 24 '19 at 07:55
-
Please add your script here so I can check – Dinesh Yadav Oct 31 '19 at 05:39
-
i resolve this by override shipping.js file in my custom module – HaFiz Umer Oct 31 '19 at 07:16