gpt4 book ai didi

php - Woocommerce 中的欧洲 GDPR 附加结帐验证复选框

转载 作者:可可西里 更新时间:2023-11-01 00:28:48 24 4
gpt4 key购买 nike

您好,我一直在尝试向我的 Woocommerce 结帐页面添加一个额外的条件复选框,与条款和条件相同,但包含有关新 GDPR(数据保护)的信息和指向我的隐私政策的链接。他们必须先勾选方框,然后才能结帐。

我一直在使用我在这里找到的各种代码片段,并设法添加了一个条件复选框和一些文本,但无法添加指向隐私政策的链接。我必须将它添加到结帐框下方。理想情况下,我希望将链接放在复选框旁边,就像它出现在条款和条件上一样。

如果您能帮助我们在结帐框中获取隐私页面链接,我们将不胜感激。

条件复选框隐私政策链接截图:

Conditional Checkbox Privacy policy Link

这是我目前所拥有的:

//Here is the function for adding the checkbox:
function cw_custom_checkbox_fields( $checkout ) {

echo '<div class="cw_custom_class"><h3>'.__('Give Sepration Heading: ').'</h3>';

woocommerce_form_field( 'custom_checkbox', array(
'type' => 'checkbox',
'label' => __('Agreegation Policy.'),
'required' => true,
), $checkout->get_value( 'custom_checkbox' ));

echo '</div>';
}
add_action('woocommerce_checkout_after_terms_and_conditions', 'checkout_additional_checkboxes');
function checkout_additional_checkboxes( ){
$checkbox1_text = __( "I have read and accept the Privacy Policy and understand how you manage my Data under GDPR", "woocommerce" );
?>
<p class="form-row custom-checkboxes">
<label class="woocommerce-form__label checkbox custom-one">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="custom_one" > <span><?php echo $checkbox1_text; ?></span> <span class="required">*</span>
</label>
</p>
<?php
}

add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');

function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST['custom_one'] )
wc_add_notice( __( 'You must accept "I have read and accept the Privacy Policy and understand how you manage my Data under GDPR".' ), 'error' );
}




add_filter('comment_form_defaults','isa_comment_reform');
add_action( 'woocommerce_after_checkout_form', 'wnd_checkout_message_bottom', 10 );

function wnd_checkout_message_bottom( ) {
echo '<div class="wnd-checkout-message"><h3> <a href="http://127.0.0.1/protest/privacy-policy/" target="_blank">Privacy Policy</a><br/></h3>
</div>';
}

最佳答案

更新 (2018 年 5 月 - 代码增强)

The new version of woocommerce 3.4 handle now GDPR

以下代码将根据条款和条件在结帐页面中为新的强制性欧洲 GDPR 隐私政策添加额外的验证复选框:

// Add terms and policy check box in checkout page
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'add_terms_and_policy', 20 );
function add_terms_and_policy() {
$domain = 'woocommerce';

$gdpr_private_policy_link = sprintf( '<a href="%s" target="_blank">%s</a>',
home_url("/protest/privacy-policy/"), // The button link to the GDPR privacy policy page
__( "Privacy Policy", $domain ) // The button text
);

woocommerce_form_field( 'gdpr_terms', array(
'type' => 'checkbox',
'class' => array( 'terms gdpr_terms' ),
'input_class' => array('woocommerce-form__input-checkbox'),
'label_class' => array('woocommerce-form__label-for-checkbox'),
'label' => '<span>' . sprintf(
__( "I have read and accept the %s and understand how you manage my Data under GDPR", $domain ),
$gdpr_private_policy_link
) . '</span>',
'required' => true,
), '');
}

// Validate required GDPR private policy checkbox
add_action( 'woocommerce_after_checkout_validation', 'terms_and_policy_validation', 20, 2 );
function terms_and_policy_validation( $data, $errors ) {
if ( ! isset( $_POST['gdpr_terms'] ) ){
$domain = 'woocommerce';

$gdpr_text = sprintf(
__( "I have read and accept the %s and understand how you manage my Data under GDPR", $domain ),
__( "Privacy Policy", $domain )
);

$errors->add( 'gdpr_terms', sprintf( __( 'You must accept "%s".', $domain ), $gdpr_text ), 'error' );
}
}

代码进入事件子主题(或事件主题)的 function.php 文件。测试和工作。

enter image description here

如果未选中,客户将收到此避免结账的错误消息:

enter image description here

关于php - Woocommerce 中的欧洲 GDPR 附加结帐验证复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49494935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com