WordPress 4.0 + WooCommerce 2.2.2~2.2.4 版, 這時的結帳畫面 (Checkout) 帳單資訊右方的『配送到不同的地址』跟過去不同, 預設被打勾了。雖然會這樣做是有一些原因, 然而我就是不希望預設是勾選的。(Ship to a Different Address checkbox is checked by default)
而修改的方式一是使用 add_filter 方式加在 function.php 裡,
To disable: 不勾選
add_filter( ‘woocommerce_ship_to_different_address_checked’, ‘__return_false’ );To enable: 被勾選
add_filter( ‘woocommerce_ship_to_different_address_checked’, ‘__return_true’ );另一個方法是直接去修改 form-shipping.php ,
位在 /htdocs/wp-content/plugins/woocommerce/templates/checkout/form-shipping.php 第30行
<input id="ship-to-different-address-checkbox" class="input-checkbox" <?php checked( $ship_to_different_address, 1 ); ?> type="checkbox" name="ship_to_different_address" value="1″ />
改成
<input id="ship-to-different-address-checkbox" class="input-checkbox" <?php checked( $ship_to_different_address, 0 ); ?> type="checkbox" name="ship_to_different_address" value="1″ />完成!
番外篇, 如果多加上 style="display:none" 則可改變外觀, 連勾選框都不見了, 只要點選『配送到不同的地址?』 文字就如同 CheckBox。
<input id="ship-to-different-address-checkbox" class="input-checkbox" style="display:none" <?php checked( $ship_to_different_address, 0 ); ?> type="checkbox" name="ship_to_different_address" value="1″ />
參考
https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-shipping.php
你好.
感謝妳的教學. 我嘗試了一下無法成功預設取消後稍微搜尋了一下
看到別人也有PO一樣的並且測試成功.
我把二個語法擺在一起後發現錯誤在於逗點而已
你的語法
add_filter( ‘woocommerce_ship_to_different_address_checked’, ‘__return_false’ );
國外我找到的
add_filter( ‘woocommerce_ship_to_different_address_checked’, ‘__return_true’ );
真的謝謝你的文章
讚讚
可能只是文章貼在WP上受到影響吧
讚讚
我自己在嘗試一次沒錯的確是WP上文章的影響.
讚讚