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

@ -194,28 +194,48 @@ function woocommerce_admin_fields($options) {
</tr><?php
break;
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')) :
?>
<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>
<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
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'] ?>">
<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>
</fieldset>
<?php
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup']=='end')) :
?>
</td>
</fieldset>
</td>
</tr>
<?php
else :
?>
</fieldset>
<?php
endif;
break;

View File

@ -89,38 +89,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
'std' => '',
'type' => 'multi_select_countries'
),
array(
'name' => __( 'Checkout', '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(
'name' => __( 'Checkout Fields', 'woothemes' ),
'desc' => __( 'Enable coupon form on checkout', 'woothemes' ),
'id' => 'woocommerce_enable_coupon_form_on_checkout',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => ''
),
array(
'desc' => __( '"Ship to same address option" checked by default', 'woothemes' ),
'id' => 'woocommerce_ship_to_same_address',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => ''
'checkboxgroup' => 'start'
),
array(
@ -132,11 +108,21 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
),
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' ),
'id' => 'woocommerce_force_ssl_checkout',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => ''
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
@ -144,9 +130,10 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
'id' => 'woocommerce_unforce_ssl_checkout',
'std' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end'
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),
array(
'name' => __( 'Customer Accounts', 'woothemes' ),
'desc' => __( 'Allow unregistered users to register from the My Account page', 'woothemes' ),
@ -718,7 +705,16 @@ $woocommerce_settings['shipping'] = apply_filters('woocommerce_shipping_settings
'desc' => __( 'Only ship to the users billing address', 'woothemes' ),
'id' => 'woocommerce_ship_to_billing_address_only',
'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' ),

View File

@ -117,5 +117,26 @@ jQuery(function(){
jQuery(this).closest('tr').next('tr').hide();
}
}).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