英文:
Add “checkbox” to policy line. Woocommerce, Botiga theme-template
问题
以下是您要翻译的内容:
"I would like to implement a checkbox icon, in the same way as the Botiga theme.
I’ve added a code snippet, and an additional checkbox "Policy terms" appears.
But I can’t figure out about the CSS, the checkbox is not visible.
I think the problem is here:
<input type="checkbox" class="input-checkbox woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" id="privacy_policy" value="1">
``` And it should be:
```html
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" id="privacy_policy" value="1">
``` I don't know how to remove "input-checkbox" value class attribute.
Here is my code snippet:
```php
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'add_privacy_block', 9 );
function add_privacy_block() {
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' => 'Я прочитал и согласен с <a href="https://genreeds.ru/politic-conf/"><b>политикой конфиденциальности</b></a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'Вам необходимо отметить галочкой, что вы ознакомлены с политикой конфиденциальности' ), 'error' );
}
}
Here is the linked page with this issue.
I can make a standard checkbox, but then I need to change the checkbox that comes with the theme above.
Probably easier to achieve that if that additional checkbox with the "botiga" is displayed?
I think the solution is very simple, but I don't have enough knowledge. Any help is appreciated."
更新:
变体1
If I add "label_class_disabled" to the snippet, then the checkbox appears. But he has a different design, standard.
变体2
Code the Policy checkbox
And here is how the checkbox code looks like that WORKS
英文:
I would like to implement a checkbox icon, in the same way as the Botiga theme.
I’ve added a code snippet, and an additional checkbox "Policy terms" appears.
But I can’t figure out about the CSS, the checkbox is not visible.
I think the problem is here:
<input type="checkbox" class="input-checkbox woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" id="privacy_policy" value="1">
And it should be:
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" id="privacy_policy" value="1">
I don't know how to remove "input-checkbox" value class attribute.
Here is my code snippet:
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'add_privacy_block', 9 );
function add_privacy_block() {
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' => 'Я прочитал и согласен с <a href="https://genreeds.ru/politic-conf/"><b>политикой конфиденциальности</b></a>',
));
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
function privacy_checkbox_error_message() {
if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'Вам необходимо отметить галочкой, что вы ознакомлены с политикой конфиденциальности' ), 'error' );
}
}
Here is the linked page with this issue.
I can make a standard checkbox, but then I need to change the checkbox that comes with the theme above.
Probably easier to achieve that if that additional checkbox with the "botiga" is displayed?
I think the solution is very simple, but I don't have enough knowledge. Any help is appreciated.
Update:
Variant 1
If I add "label_class_disabled" to the snippet, then the checkbox appears. But he has a different design, standard.
Variant 2
Code the Policy checkbox
And here is how the checkbox code looks like that WORKS
答案1
得分: 2
在结账页面中,WooCommerce的服务条款复选框的代码位于terms.php WooCommerce模板文件中。
在您的主要函数中,我已经为您的“政策”复选框使用了类似的代码,并且我还稍微修改了您的另一个函数。
add_action('woocommerce_checkout_after_terms_and_conditions', 'privacy_checkbox_block');
function privacy_checkbox_block() {
$checkbox_text = sprintf('%s <a href="%s"><strong>%s</strong></a>', __('Я прочитал и согласен с'),
esc_url(site_url('/politic-conf/')), __('политикой конфиденциальности'));
?>
<div class="woocommerce-privacy-policy-wrapper">
<p class="form-row validate-required">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" <?php checked(false, true); ?> id="privacy-policy" />
<span class="woocommerce-privacy-policy-checkbox-text"><?php echo $checkbox_text; ?></span> <abbr class="required" title="<?php esc_attr_e('required', 'woocommerce'); ?>">*</abbr>
</label>
<input type="hidden" name="policy-field" value="1" />
</p>
</div>
<?php
}
add_action('woocommerce_checkout_process', 'privacy_checkbox_validation');
function privacy_checkbox_validation() {
if (!isset($_POST['privacy_policy'])) {
wc_add_notice(__('Вам необходимо отметить галочкой, что вы ознакомлены с политикой конфиденциальности'), 'error');
}
}
现在应该可以正常工作并且可见… 验证也有效。
1: https://github.com/woocommerce/woocommerce/blob/release/7.8/plugins/woocommerce/templates/checkout/terms.php
英文:
The code of WooCommerce terms and conditions checkbox in Checkout page is located in terms.php WooCommerce template file.
On your main function, I have used a similar code for your "policy" checkbox, and I have changed a bit your other function too.
add_action( 'woocommerce_checkout_after_terms_and_conditions', 'privacy_checkbox_block' );
function privacy_checkbox_block() {
$checkbox_text = sprintf( '%s <a href="%s"><strong>%s</strong></a>', __( 'Я прочитал и согласен с' ),
esc_url( site_url('/politic-conf/') ), __( 'политикой конфиденциальности' ) );
?>
<div class="woocommerce-privacy-policy-wrapper">
<p class="form-row validate-required">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="privacy_policy" <?php checked( false, true ); ?> id="privacy-policy" />
<span class="woocommerce-privacy-policy-checkbox-text"><?php echo $checkbox_text; ?></span>&nbsp;<abbr class="required" title="<?php esc_attr_e( 'required', 'woocommerce' ); ?>">*</abbr>
</label>
<input type="hidden" name="policy-field" value="1" />
</p>
</div>
<?php
}
add_action( 'woocommerce_checkout_process', 'privacy_checkbox_validation' );
function privacy_checkbox_validation() {
if ( ! isset( $_POST['privacy_policy'] ) ) {
wc_add_notice( __( 'Вам необходимо отметить галочкой, что вы ознакомлены с политикой конфиденциальности' ), 'error' );
}
}
It should work now and be visible… The validation works too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论