Conditional options

This commit is contained in:
Mike Jolley 2011-12-21 21:12:34 +00:00
parent d8a985fad7
commit cc91cf5618
4 changed files with 73 additions and 36 deletions

View File

@ -195,27 +195,47 @@ function woocommerce_admin_fields($options) {
break; break;
case 'checkbox' : case 'checkbox' :
if (!isset($value['hide_if_checked'])) $value['hide_if_checked'] = false;
if (!isset($value['show_if_checked'])) $value['show_if_checked'] = false;
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='start')) : if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='start')) :
?> ?>
<tr valign="top"> <tr valign="top" class="<?php
if ($value['hide_if_checked']=='yes' || $value['show_if_checked']=='yes') echo 'hidden_option';
if ($value['hide_if_checked']=='option') echo 'hide_options_if_checked';
if ($value['show_if_checked']=='option') echo 'show_options_if_checked';
?>">
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th> <th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
<td class="forminp"> <td class="forminp">
<fieldset>
<?php
else :
?>
<fieldset class="<?php
if ($value['hide_if_checked']=='yes' || $value['show_if_checked']=='yes') echo 'hidden_option';
if ($value['hide_if_checked']=='option') echo 'hide_options_if_checked';
if ($value['show_if_checked']=='option') echo 'show_options_if_checked';
?>">
<?php <?php
endif; endif;
?> ?>
<fieldset><legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend> <legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend>
<label for="<?php echo $value['id'] ?>"> <label for="<?php echo $value['id'] ?>">
<input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="checkbox" value="1" <?php checked(get_option($value['id']), 'yes'); ?> /> <input name="<?php echo esc_attr( $value['id'] ); ?>" id="<?php echo esc_attr( $value['id'] ); ?>" type="checkbox" value="1" <?php checked(get_option($value['id']), 'yes'); ?> />
<?php echo $value['desc'] ?></label><br> <?php echo $value['desc'] ?></label><br>
</fieldset>
<?php <?php
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='end')) : if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='end')) :
?> ?>
</fieldset>
</td> </td>
</tr> </tr>
<?php <?php
else :
?>
</fieldset>
<?php
endif; endif;
break; break;

View File

@ -91,36 +91,12 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
), ),
array( array(
'name' => __( 'Checkout', 'woothemes' ), 'name' => __( 'Checkout Fields', 'woothemes' ),
'desc' => __( 'Allow users to checkout without signing up for an account', 'woothemes' ),
'id' => 'woocommerce_enable_guest_checkout',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start'
),
array(
'desc' => __( 'Allow users to create an account and login from the checkout page', 'woothemes' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => ''
),
array(
'desc' => __( 'Enable coupon form on checkout', 'woothemes' ), 'desc' => __( 'Enable coupon form on checkout', 'woothemes' ),
'id' => 'woocommerce_enable_coupon_form_on_checkout', 'id' => 'woocommerce_enable_coupon_form_on_checkout',
'std' => 'no', 'std' => 'no',
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => '' 'checkboxgroup' => 'start'
),
array(
'desc' => __( '"Ship to same address option" checked by default', 'woothemes' ),
'id' => 'woocommerce_ship_to_same_address',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => ''
), ),
array( array(
@ -132,11 +108,21 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
), ),
array( array(
'desc' => __( 'Allow unregistered users to register from the checkout page', 'woothemes' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end'
),
array(
'name' => __( 'Security', 'woothemes' ),
'desc' => __( 'Force <abbr title="Secure Sockets Layer, a computing protocol that ensures the security of data sent via the Internet by using encryption">SSL</abbr>/HTTPS (an SSL Certificate is required)', 'woothemes' ), 'desc' => __( 'Force <abbr title="Secure Sockets Layer, a computing protocol that ensures the security of data sent via the Internet by using encryption">SSL</abbr>/HTTPS (an SSL Certificate is required)', 'woothemes' ),
'id' => 'woocommerce_force_ssl_checkout', 'id' => 'woocommerce_force_ssl_checkout',
'std' => 'no', 'std' => 'no',
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => '' 'checkboxgroup' => 'start',
'show_if_checked' => 'option',
), ),
array( array(
@ -144,7 +130,8 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
'id' => 'woocommerce_unforce_ssl_checkout', 'id' => 'woocommerce_unforce_ssl_checkout',
'std' => 'no', 'std' => 'no',
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => 'end' 'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
), ),
array( array(
@ -718,7 +705,16 @@ $woocommerce_settings['shipping'] = apply_filters('woocommerce_shipping_settings
'desc' => __( 'Only ship to the users billing address', 'woothemes' ), 'desc' => __( 'Only ship to the users billing address', 'woothemes' ),
'id' => 'woocommerce_ship_to_billing_address_only', 'id' => 'woocommerce_ship_to_billing_address_only',
'std' => 'no', 'std' => 'no',
'type' => 'checkbox' 'type' => 'checkbox',
'checkboxgroup' => 'start'
),
array(
'desc' => __( 'Ship to billing address by default', 'woothemes' ),
'id' => 'woocommerce_ship_to_same_address',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end'
), ),
array( 'type' => 'sectionend', 'id' => 'shipping_options' ), array( 'type' => 'sectionend', 'id' => 'shipping_options' ),

View File

@ -118,4 +118,25 @@ jQuery(function(){
} }
}).change(); }).change();
// Hidden options
jQuery('.hide_options_if_checked input:eq(0)').change(function() {
if (jQuery(this).is(':checked')) {
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
} else {
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
}
}).change();
jQuery('.show_options_if_checked input:eq(0)').change(function() {
if (jQuery(this).is(':checked')) {
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').show();
} else {
jQuery(this).closest('fieldset, tr').nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option').hide();
}
}).change();
}); });

File diff suppressed because one or more lines are too long