搜索

首页  >  问答  >  正文

Woocommerce 结帐字段保持更改

<p>我使用此代码来更改我的结帐字段布局,使用我在产品页面 [woocommerce_checkout] 中放入的 Woocommerce Checkout 短代码,它看起来不错,但在结帐页面中则不然,1 秒后会变回原始状态。我尝试更改主题并禁用除 Woocommerce 之外的所有插件,仍然发生。如何解决这个问题?</p> <pre class="brush:php;toolbar:false;">/**删除所有可能的字段 **/ 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' );</pre> <p> 带有简码并在结账页面首次查看</p> <p> 结账页面1秒后更改</p> <p> 在浏览器上禁用 JavaScript 后</p>
P粉394812277P粉394812277460 天前519

全部回复(1)我来回复

  • P粉617597173

    P粉6175971732023-09-01 12:25:19

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

    add_action( 'wp_enqueue_scripts', 'remove_woocommerce_checkout_scripts', 9999 );
    function remove_woocommerce_checkout_scripts() {
        wp_dequeue_script( 'wc-checkout' );
    }

    回复
    0
  • 取消回复