Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created January 26, 2020 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/4e9dffcf4fc20dba2ddd2065666ca2bd to your computer and use it in GitHub Desktop.
Save plugin-republic/4e9dffcf4fc20dba2ddd2065666ca2bd to your computer and use it in GitHub Desktop.
<?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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment