将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

huangapple go评论80阅读模式
英文:

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

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

If I add "label_class_disabled" to the snippet, then the checkbox appears. But he has a different design, standard.

变体2

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

Code the Policy checkbox

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

And here is how the checkbox code looks like that WORKS

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

英文:

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

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

If I add "label_class_disabled" to the snippet, then the checkbox appears. But he has a different design, standard.

Variant 2

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

Code the Policy checkbox

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

And here is how the checkbox code looks like that WORKS

将“checkbox”添加到政策行。WooCommerce,Botiga主题模板。

答案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>&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');
    }
}

现在应该可以正常工作并且可见… 验证也有效。
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( &#39;woocommerce_checkout_after_terms_and_conditions&#39;, &#39;privacy_checkbox_block&#39; );
function privacy_checkbox_block() {
    $checkbox_text = sprintf( &#39;%s &lt;a href=&quot;%s&quot;&gt;&lt;strong&gt;%s&lt;/strong&gt;&lt;/a&gt;&#39;, __( &#39;Я прочитал и согласен с&#39; ), 
    esc_url( site_url(&#39;/politic-conf/&#39;) ), __( &#39;политикой конфиденциальности&#39; ) );
	?&gt;
	&lt;div class=&quot;woocommerce-privacy-policy-wrapper&quot;&gt;
		&lt;p class=&quot;form-row validate-required&quot;&gt;
			&lt;label class=&quot;woocommerce-form__label woocommerce-form__label-for-checkbox checkbox&quot;&gt;
			&lt;input type=&quot;checkbox&quot; class=&quot;woocommerce-form__input woocommerce-form__input-checkbox input-checkbox&quot; name=&quot;privacy_policy&quot; &lt;?php checked( false, true ); ?&gt; id=&quot;privacy-policy&quot; /&gt;
				&lt;span class=&quot;woocommerce-privacy-policy-checkbox-text&quot;&gt;&lt;?php echo $checkbox_text; ?&gt;&lt;/span&gt;&amp;nbsp;&lt;abbr class=&quot;required&quot; title=&quot;&lt;?php esc_attr_e( &#39;required&#39;, &#39;woocommerce&#39; ); ?&gt;&quot;&gt;*&lt;/abbr&gt;
			&lt;/label&gt;
			&lt;input type=&quot;hidden&quot; name=&quot;policy-field&quot; value=&quot;1&quot; /&gt;
		&lt;/p&gt;
	&lt;/div&gt;
	&lt;?php
}

add_action( &#39;woocommerce_checkout_process&#39;, &#39;privacy_checkbox_validation&#39; );
function privacy_checkbox_validation() {
    if ( ! isset( $_POST[&#39;privacy_policy&#39;] ) ) {
        wc_add_notice( __( &#39;Вам необходимо отметить галочкой, что вы ознакомлены с политикой конфиденциальности&#39; ), &#39;error&#39; );
    }
}

It should work now and be visible… The validation works too.

huangapple
  • 本文由 发表于 2023年6月25日 23:31:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定