Woocommerce 結帳欄位保持更改
P粉394812277
2023-08-31 23:23:19
<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>
我嘗試用這個刪除 wc-checkout 腳本,佈局變成我想要的