【发布时间】:2016-08-01 20:47:12
【问题描述】:
我一直在尝试修改 WooCommerce,以显示礼物复选框。到目前为止,它正在显示它,但是当我单击复选框时它没有隐藏/显示它。
我在 functions.php 上使用的代码是:
/**
* Add the field to the checkout
**/
add_action( 'woocommerce_after_order_notes','wordimpress_custom_checkout_field' );
function wordimpress_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>' . __( 'Is this a gift?' ) . '</h3><p style="margin: 0 0 8px;">Please check below to indicate if this is a gift</p>';
woocommerce_form_field( 'gift_checkbox', array(
'type' => 'checkbox',
'class' => array( 'gift-checkbox form-row-wide' ),
'label' => __( 'Yes' ),
), $checkout->get_value( 'gift_checkbox' ) );
woocommerce_form_field( 'to_textbox', array(
'type' => 'text',
'class' => array( 'to-text form-row-wide' ),
'label' => __( 'To' ),
), $checkout->get_value( 'to_textbox' ) );
woocommerce_form_field( 'from_textbox', array(
'type' => 'text',
'class' => array( 'from-text form-row-wide' ),
'label' => __( 'From' ),
), $checkout->get_value( 'from_textbox' ) );
woocommerce_form_field( 'message_textbox', array(
'type' => 'text',
'class' => array( 'message-text form-row-wide' ),
'label' => __( 'Message' ),
), $checkout->get_value( 'message_text' ) );
echo '</div>';
}
现在我尝试将其隐藏在 css witht 中:
.to-text{ display:none; }
.from-text{ display:none; }
.message-text{ display:none; }
我在 script.js 中使用的 jQuery 代码是:
$( ".gift-checkbox " ).click(function() {
$( ".to-text form-row-wide" ).slideToggle();
$( ".from-text form-row-wide" ).slideToggle();
$( ".message-text form-row-wide" ).slideToggle();
});
我做错了什么?
我不明白为什么不起作用。
【问题讨论】:
标签: php jquery css wordpress woocommerce