Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce Checkout Add-ons conditional display
/**
* Conditionally show gift add-ons if shipping address differs from billing
**/
function wc_checkout_add_ons_conditionally_show_gift_add_on() {
wc_enqueue_js( "
$( 'input[name=ship_to_different_address]' ).change( function () {
if ( $( this ).is( ':checked' ) ) {
// show the gift checkout add-on -- replace '2' with the id of your add-on
$( '#wc_checkout_add_ons_2_field' ).show();
} else {
// hide the gift checkout add-on -- replace '2' with the id of your add-on
$( '#wc_checkout_add_ons_2_field' ).hide();
}
} ).change();
" );
}
add_action( 'wp_enqueue_scripts', 'wc_checkout_add_ons_conditionally_show_gift_add_on' );
Copy link

ghost commented Nov 1, 2015

I want to hide some field that I've created by "WooCommerce Checkout Add-Ons" Plugin

Is there any way to do this?

http://i.imgur.com/YRlzfZE.jpg

@username390
Copy link

username390 commented Jul 24, 2017

WooCommerce Checkout Add-ons conditional display
how would I edit this to only display gift wrap options if "gift wrap" box is checked?

@LassosLabs
Copy link

LassosLabs commented Oct 12, 2017

For conditionally show another custom addon just change the name of the field "name=ship_to_different_address" to, in my case name=wc_checkout_add_ons_3, beign the option i want to be the trigger.. for example,:

wc_enqueue_js( "
$( 'input[name=wc_checkout_add_ons_3]' ).change( function () {

This for the addon ID nº 3, if u set that , when checked that option condition will ocurr

U just need to change the "name" field

Excuse my poor english

@AlexandruNacu
Copy link

AlexandruNacu commented Jan 29, 2018

Hello,

i want to hide import add on field 6 if the country selected is Romanaia
and is not working
`wc_enqueue_js( "
$( 'input[name=billing_country]' ).change( function () {

        if ( $( this ).is( ':select2-billing_country-result-pr8d-RO' ) ) {

            // show the gift checkout add-on -- replace '6' with the id of your add-on
            $( '#wc_checkout_add_ons_6_field' ).hide();

        } else {

            // hide the gift checkout add-on -- replace '6' with the id of your add-on
            $( '#wc_checkout_add_ons_6_field' ).show();

        }

    } ).change();
" );

}
add_action( 'wp_enqueue_scripts', 'wc_checkout_add_ons_conditionally_hide_import_add_on' );
`

@schalkjoubert
Copy link

schalkjoubert commented Sep 13, 2018

Hi,
I have 2 fields
1: A file upload Field: Please upload your ID.
2: A checkbox field. Please confirm that this is a true copy of your ID

Since ID is optional field, i want the Checkbox to only show if the user uploaded an ID.
Possible?
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment