How to automatically select checkout options in opencart?

廉价感情. 提交于 2019-12-19 04:50:31

问题


In the shop I'm developing, users can only see prices and add products to cart only if they create an account. After that, they can add products to cart. The options Billing Details & Delivery Details are automatically filled in with the user's address. The delivery method is free and the payment method is "cash on delivery".

How can I automatically select these options and hide them so the only step left would be to Confirm the order?

I assume the template file I need to change is catalog/view/theme/default/template/checkout/checkout.tpl but it's almost a 1k lines long and uses ajax which I don't know...

I've been trying to do this for a few hours so any help would be greatly appreciated!

Thank you very much!


回答1:


In case someone stumbles upon this question, I found the answer here. It works for account option, shipping option, payment option but it doesn't work for step2-billing option (if you try to click the continue button in step2 with jquery it just sends it into an infinite loop).

The solution: You basically click the Continue button with Jquery and then hide the respective step/steps with CSS (/catalog/view/theme/default/stylesheet/stylesheet.css):

#checkout, #payment-method {
    display:none;
}

The following is from the opencart community forum:

To skip the account option just copy paste this code on the top of the catalog/view/theme/default/template/checkout/login.tpl:

<script language="Javascript" type="text/javascript">
$(document).ready(function(){
  $('#button-account').trigger('click');
});
</script>

Remember to have a look to some older post I have done to autoselect login options.

To skip the shipping option just copy paste this code on the top of the catalog/view/theme/default/template/checkout/shipping.tpl:

<script language="Javascript" type="text/javascript">
$(document).ready(function(){
  $('#button-shipping').trigger('click');
});
</script>

To skip the payment option just copy paste this code on the top of the catalog/view/theme/default/template/checkout/payment.tpl:

<script language="Javascript" type="text/javascript">
$(document).ready(function(){
  $('#button-payment').trigger('click');
});
</script>

In these case, in opencart 1.5 you also will have to change this code (line 36):

<input type="checkbox" name="agree" value="1"/>

to this one:

<input type="checkbox" name="agree" value="1" checked="checked"/>

Remember that these tricks will only work if the default option is the one you want (or if you force opencart to autoselect one concrete option).




回答2:


In Opencart 1.5.2.1 some of the button names may have been changed.

The Account button stayed the same.

To remove payment method:

<script language="Javascript" type="text/javascript">
    $(document).ready(function(){
        $('#button-payment-method').trigger('click');
    });
</script>

To remove shipping / delivery method:

<script language="Javascript" type="text/javascript">
    $(document).ready(function(){
        $('#button-shipping-method').trigger('click');
    });
</script>

Check each button to see if the Javascript provided is actually calling the id of the button desired.

The associated CSS should look like this:

/* Modified checkout */

#shipping-method, #payment-method {
    display:none;
}


来源:https://stackoverflow.com/questions/8747327/how-to-automatically-select-checkout-options-in-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!