Maybe you want to display fields that would otherwise be hidden (because they’re conditional on another field’s value). This code snippet keeps all fields visible, but disables and greys out fields that are unavailable:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display hidden fields as disabled | |
*/ | |
function prefix_disable_hidden_fields() { ?> | |
<script> | |
jQuery( document ).ready( function( $ ) { | |
function disableHiddenFields(){ | |
$( 'form.cart' ).find( '.pewc-hidden-field' ).each( function() { | |
// Display and disable hidden fields | |
$( this ).show().css( { visibility: 'visible', opacity: 0.5 } ).find( '.pewc-form-field' ).prop( 'disabled', true ); | |
}); | |
} | |
$( '.pewc-form-field, .pewc-radio-form-field' ).on( 'change update', function() { | |
$( 'form.cart' ).find( '.pewc-item' ).each( function() { | |
// Reset fields | |
$( this ).css( { opacity: 1 } ).find( '.pewc-form-field' ).prop( 'disabled', false ); | |
}); | |
// Set a delay to let the plugin do its stuff first | |
setTimeout( disableHiddenFields, 150 ); | |
}); | |
disableHiddenFields(); | |
}); | |
</script> | |
<?php } | |
add_action( 'pewc_after_product_fields', 'prefix_disable_hidden_fields' ); |
Here’s how to add a snippet.
Related Articles
-
How to display add-on fields in Germanized for WooCommerce invoices
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document
-
Remove quantity field from WooCommerce product
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document
-
Add-on field validation
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document
-
Hiding add-on field and option prices
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document
-
Optimising calculations and conditions
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document
-
Display field description as placeholder
- Plugin: WooCommerce Product Add-Ons Ultimate
- Content Type: Support Document