gpt4 book ai didi

wordpress - 将自定义 CSS 类添加到 WooCommerce 结帐字段

转载 作者:行者123 更新时间:2023-12-03 22:46:51 26 4
gpt4 key购买 nike

我希望能够将自定义 CSS 类添加到我的 WooCommerce 结帐字段。我正在使用 twitter Bootstrap,我希望能够使用他们的 .form-control 类。

我查看了 form-billing.php 中的 woocommerce 模板文件夹但我不确定在哪里添加 .form-control类到每个文本字段。

这是 form-billing.php 的代码

<?php
/**
* Checkout billing information form
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1.2
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
<div class="woocommerce-billing-fields">
<?php if ( WC()->cart->ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>

<h3><?php _e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>

<?php else : ?>

<h3><?php _e( 'Billing Details', 'woocommerce' ); ?></h3>

<?php endif; ?>

<?php do_action( 'woocommerce_before_checkout_billing_form', $checkout ); ?>

<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>

<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

<?php endforeach; ?>

<?php do_action('woocommerce_after_checkout_billing_form', $checkout ); ?>

<?php if ( ! is_user_logged_in() && $checkout->enable_signup ) : ?>

<?php if ( $checkout->enable_guest_checkout ) : ?>

<p class="form-row form-row-wide create-account">
<input class="input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label>
</p>

<?php endif; ?>

<?php do_action( 'woocommerce_before_checkout_registration_form', $checkout ); ?>

<?php if ( ! empty( $checkout->checkout_fields['account'] ) ) : ?>

<div class="create-account">

<p><?php _e( 'Create an account by entering the information below. If you are a returning customer please login at the top of the page.', 'woocommerce' ); ?></p>

<?php foreach ( $checkout->checkout_fields['account'] as $key => $field ) : ?>

<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

<?php endforeach; ?>

<div class="clear"></div>

</div>

<?php endif; ?>

<?php do_action( 'woocommerce_after_checkout_registration_form', $checkout ); ?>

<?php endif; ?>
</div>

我需要查看另一个模板文件吗?

谢谢

最佳答案

icc97 的答案几乎就在那里,但不起作用。

我接受了 icc97 的回答,并对其进行了调试:

add_filter('woocommerce_checkout_fields', 'addBootstrapToCheckoutFields' );
public function addBootstrapToCheckoutFields($fields) {
foreach ($fields as &$fieldset) {
foreach ($fieldset as &$field) {
// if you want to add the form-group class around the label and the input
$field['class'][] = 'form-group';

// add form-control to the actual input
$field['input_class'][] = 'form-control';
}
}
return $fields;
}

关于wordpress - 将自定义 CSS 类添加到 WooCommerce 结帐字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23943791/

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