Hello
Just installed the latest version of WooCommerce, which by default activated coupon codes with JS.
For some reason this doesn't work properly.. and I want to use the non-js way to do it.
(tested with turning of javascript in my browser and then it works fine)
Soo.. how can I turn of JS for this exact function?
You can test the site here: http://2016-maj.maybeauty.se/varukorg-kassa/?add-to-cart=2453
P.S. Also want to be able to delete the coupon code non-js style.
Rempty answers:
Do you have a coupon code to test?
FirstEntertainment comments:
yes sorry.. please you code:
foki
Rempty comments:
If you want to hide the coupon if there is one applied, add this code to your functions.php:
function rem_hide_coupon(){
if(WC()->cart->applied_coupons && is_checkout()){
?>
<script type='text/javascript'>
jQuery( document ).ready( function( ) {
jQuery( 'form.checkout_coupon' ).attr('style','display:none!important');
} );
</script>
<?php
}
}
add_action( 'wp_footer', 'rem_hide_coupon', 99 );
dimadin answers:
Try this:
function md_woo_no_coupon_js() {
wp_print_scripts( 'jquery' );
?>
<script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
$( '.woocommerce-remove-coupon' ).off();
$( 'form.checkout_coupon' ).off();
} );
</script>
<?php
}
add_action( 'wp_footer', 'md_woo_no_coupon_js', 999 );
If deletion of coupon still work over JS, add this too:
function md_woo_no_coupon_remove_js( $html ) {
return str_replace( 'woocommerce-remove-coupon', '', $html );
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'md_woo_no_coupon_remove_js' );
dimadin comments:
Hey FirstEntertainment, did code I posted here worked?
FirstEntertainment comments:
Thanks! This worked.
Have some WC jobs for you if interested.. sent you an email ;)
FirstEntertainment comments:
Also.. had a new tiny problem that perhaps someone can help me with..
Before I had this simple code:
if(empty ($woocommerce->cart->applied_coupons)) {
Cart Coupon Code here
Basically if a coupon is already applied, we don't see the form. From latest version of woocommerce this stopped working.
dimadin comments:
Although not related to original question: instead of
if(empty ($woocommerce->cart->applied_coupons)) {
you should use
if ( ! WC()->cart->applied_coupons ) {
And generally, instead of using $woocommerce global you should just use WC() function.
Bob answers:
this might be helpful
[[LINK href="http://stackoverflow.com/questions/30626895/woocommerce-how-to-disable-ajax-on-apply-remove-coupon"]]http://stackoverflow.com/questions/30626895/woocommerce-how-to-disable-ajax-on-apply-remove-coupon[[/LINK]]
or you can even stop loading checkout js
[[LINK href="http://stackoverflow.com/questions/27023433/disable-ajax-on-checkout-for-woocommerce"]]http://stackoverflow.com/questions/27023433/disable-ajax-on-checkout-for-woocommerce[[/LINK]]
theme's functions.php code
function so_27023433_disable_checkout_script(){
wp_dequeue_script( 'wc-checkout' );
}
add_action( 'wp_enqueue_scripts', 'so_27023433_disable_checkout_script' );
FirstEntertainment comments:
Thanks Bob
I just wanted to disable these things, so dimadin's solution worked well here.
Bob comments:
Great! :)