Woocommerce 结帐字段保持更改
P粉394812277
P粉394812277 2023-08-31 23:23:19
[PHP讨论组]

我使用此代码来更改我的结帐字段布局,使用我在产品页面 [woocommerce_checkout] 中放入的 Woocommerce Checkout 短代码,它看起来不错,但在结帐页面中则不然,1 秒后会变回原始状态。我尝试更改主题并禁用除 Woocommerce 之外的所有插件,仍然发生。如何解决这个问题?

/**
 Remove all possible fields
 **/
function wc_checkout_fields( $fields ) {
echo '<style>       
.woocommerce-additional-fields {
    display: none;
}
.woocommerce-checkout #customer_details>* {
    margin-bottom: 1rem !important;
}
</style>';
$fields['billing']['billing_first_name']['priority'] = 10;
$fields['billing']['billing_first_name']['label'] = 'Name';
$fields['billing']['billing_first_name']['class'] = array( 'form-row-wide' );

$fields['billing']['billing_address_1']['priority'] = 20;
$fields['billing']['billing_address_1']['label'] = 'Address';

$fields['billing']['billing_country']['priority'] = 30;
$fields['billing']['billing_country']['label'] = 'Country';
$fields['billing']['billing_country']['class'] = array( 'form-row-first' );

$fields['billing']['billing_state']['priority'] = 40;
$fields['billing']['billing_state']['label'] = 'State';
$fields['billing']['billing_state']['class'] = array( 'form-row-last' );

$fields['billing']['billing_city']['priority'] = 50;
$fields['billing']['billing_city']['label'] = 'City';
$fields['billing']['billing_city']['class'] = array( 'form-row-first' );

$fields['billing']['billing_postcode']['priority'] = 60;
$fields['billing']['billing_postcode']['label'] = 'Postcode';
$fields['billing']['billing_postcode']['class'] = array( 'form-row-last' );

$fields['billing']['billing_phone']['priority'] = 70;
$fields['billing']['billing_phone']['label'] = 'Phone';
$fields['billing']['billing_phone']['class'] = array( 'form-row-first' );

$fields['billing']['billing_email']['priority'] = 80;
$fields['billing']['billing_email']['label'] = 'Email';
$fields['billing']['billing_email']['class'] = array( 'form-row-last' );

unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_company'] );
unset( $fields['order']['order_comments'] );

return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'wc_checkout_fields' );

带有简码并在结账页面首次查看

结账页面1秒后更改

在浏览器上禁用 JavaScript 后

P粉394812277
P粉394812277

全部回复(1)
P粉617597173

我尝试用这个删除 wc-checkout 脚本,布局变成我想要的

add_action( 'wp_enqueue_scripts', 'remove_woocommerce_checkout_scripts', 9999 );
function remove_woocommerce_checkout_scripts() {
    wp_dequeue_script( 'wc-checkout' );
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号