admin管理员组文章数量:1130349
I've added a checkbox on the checkout page by using this :
add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
function add_privacy_checkbox() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'I\'ve read and accept the <a href="">Privacy Policy</a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'You have to agree to our privacy policy in order to proceed' ), 'error' );
}
}
I want to make the checkout button disabled until the user has checked the "I've read and accept the privacy policy. What would be the best practice of doing this? With jQuery it would be the simplest way, but could it be done direct with php?
I've added a checkbox on the checkout page by using this :
add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
function add_privacy_checkbox() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'I\'ve read and accept the <a href="https://website/privacy-policy">Privacy Policy</a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'You have to agree to our privacy policy in order to proceed' ), 'error' );
}
}
I want to make the checkout button disabled until the user has checked the "I've read and accept the privacy policy. What would be the best practice of doing this? With jQuery it would be the simplest way, but could it be done direct with php?
Share Improve this question asked Nov 21, 2018 at 11:21 user3211760user3211760 111 silver badge2 bronze badges 1- Woocommerce has that feature inbuild? just make sure that page is set for privacy policy – user145078 Commented Nov 21, 2018 at 12:09
1 Answer
Reset to default 3I think you should jQuery to enable and disable the checkout button. Please try this script.
Put this script in the footer.php.
jQuery(window).on('load',function(){
setTimeout(function(){
jQuery('#payment #place_order').attr("disabled","disabled");
console.log('Hello');
},1000);
});
jQuery(document).on('change','#privacy_policy_field #privacy_policy',function() {
var ischecked= jQuery(this).is(':checked');
if(!ischecked){
jQuery('#payment #place_order').attr("disabled","disabled");
console.log('unchecked');
}else{
jQuery('#payment #place_order').removeAttr("disabled");
console.log('checked');
}
});
Note: This is tested script for your code.
I've added a checkbox on the checkout page by using this :
add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
function add_privacy_checkbox() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'I\'ve read and accept the <a href="">Privacy Policy</a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'You have to agree to our privacy policy in order to proceed' ), 'error' );
}
}
I want to make the checkout button disabled until the user has checked the "I've read and accept the privacy policy. What would be the best practice of doing this? With jQuery it would be the simplest way, but could it be done direct with php?
I've added a checkbox on the checkout page by using this :
add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
function add_privacy_checkbox() {
woocommerce_form_field( 'privacy_policy', array(
'type' => 'checkbox',
'class' => array('form-row privacy'),
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
'required' => true,
'label' => 'I\'ve read and accept the <a href="https://website/privacy-policy">Privacy Policy</a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'You have to agree to our privacy policy in order to proceed' ), 'error' );
}
}
I want to make the checkout button disabled until the user has checked the "I've read and accept the privacy policy. What would be the best practice of doing this? With jQuery it would be the simplest way, but could it be done direct with php?
Share Improve this question asked Nov 21, 2018 at 11:21 user3211760user3211760 111 silver badge2 bronze badges 1- Woocommerce has that feature inbuild? just make sure that page is set for privacy policy – user145078 Commented Nov 21, 2018 at 12:09
1 Answer
Reset to default 3I think you should jQuery to enable and disable the checkout button. Please try this script.
Put this script in the footer.php.
jQuery(window).on('load',function(){
setTimeout(function(){
jQuery('#payment #place_order').attr("disabled","disabled");
console.log('Hello');
},1000);
});
jQuery(document).on('change','#privacy_policy_field #privacy_policy',function() {
var ischecked= jQuery(this).is(':checked');
if(!ischecked){
jQuery('#payment #place_order').attr("disabled","disabled");
console.log('unchecked');
}else{
jQuery('#payment #place_order').removeAttr("disabled");
console.log('checked');
}
});
Note: This is tested script for your code.
本文标签: Woocommercedisable 171place order187 until user checks Privacy Policy
版权声明:本文标题:Woocommerce - disable «place order» until user checks Privacy Policy 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749163515a2325788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论