[英]Custom "Terms and Conditions" acceptance checkbox in Cart page Woocommerce
[英]Moving terms & conditions checkbox to cart page - Woocommerce
我目前在結帳頁面上添加了一個復選框,以接受條款和條件。 我想將其移至購物車頁面,因此他們必須在此打鈎才能進入結帳頁面。
這是我的功能,可以嗎?
add_action('woocommerce_review_order_before_submit', 'add_checkout_tickbox', 9);
function add_checkout_tickbox() { ?>
<p class="form-row terms">
<input type="checkbox" class="input-checkbox" name="terms" id="terms" />
<label for="terms" class="checkbox">I accept I've seen the below terms</label>
<a href="/terms" class="btn-primary">See the terms</a>
</p>
<?php }
// Show notice if customer does not tick
add_action('woocommerce_checkout_process', 'not_approved');
function not_approved() {
if ( ! $_POST['terms'] )
wc_add_notice( __( 'Please acknowledge the terms and conditions' ), 'error' );
}
謝謝!
我不能說這會100%起作用,因為我自己還沒有嘗試過,但是嘗試...
如果您不是主題開發者,建議首先創建一個子主題。 如果需要,請遵循以下步驟>>>
然后,您將需要安裝WordPress插件Simply Show Hooks 。 成功安裝了所說的插件后,您只需訪問每個網頁即可查看頁面上的所有“ Hooks
和“ Actions
”。
接下來,進入您的Child主題(如果適用)中的functions.php
文件,並輸入: remove_action('woocommerce_review_order_before_submit', 'add_checkout_tickbox', 9);
這將刪除該復選框。 如果要處理Parent主題中的functions.php
文件,請確保將此條目放置在 add_action('woocommerce_review_order_before_submit', 'add_checkout_tickbox', 9);
。 對於父主題主題和子主題主題,請確保優先級數字9保持相同。
然后,您進入購物車頁面並找到相關的掛鈎,您想在其中放置復選框。 您應該看到掛鈎顯示在頁面的綠色框中。 找到掛鈎后,您只需輸入隨附的代碼,即可將woocommerce_review_order_before_submit
替換為所需的掛鈎。 例如:
add_action('YOUR_DESIRED_HOOK', 'add_checkout_tickbox', 9);
function add_checkout_tickbox() { ?>
<p class="form-row terms">
<input type="checkbox" class="input-checkbox" name="terms" id="terms" />
<label for="terms" class="checkbox">I accept I've seen the below terms</label>
<a href="/terms" class="btn-primary">See the terms</a>
</p>
<?php }
查看代碼后,您確定{ ?>
和<?php }
應該存在嗎? 這看起來像一個錯誤,但我可能是錯的。 如果這不起作用,請嘗試刪除?>
和<?php
對重新定位感到滿意后,您可以卸載/禁用Simply Show Hooks插件,直到再次需要它為止。
就像我說的,我自己還沒有做過,所以不能說它會100%工作,但請告訴我們您的情況如何。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.