0
我不知道是否有一個鉤子用於在點擊時更改「下單按鈕」行爲。我試圖在下單時更換/更換產品,因爲產品選擇(所有可用產品)也都位於結帳頁面中。針對自定義行爲的Woocommerce鉤子對於下訂單
到目前爲止,我一直試圖操縱woocommerce_checkout_order_review
掛鉤&失敗。
add_action('woocommerce_checkout_order_review', 'remove_woocommerce_product');
function remove_woocommerce_product(){
if (isset($_POST['woocommerce_checkout_place_order'])){
global $woocommerce;
$woocommerce->cart->empty_cart(); // Empty the cart
$selectedproduct = $_POST['selectedproductid']; // Get the selected product
WC()->cart->add_to_cart($selectedproduct); // Insert the selected product in the the cart
return esc_url(wc_get_checkout_url()); // Redirect to Payment Gateway Page
}
}
上面的掛鉤不會在下訂單時觸發。也許我的代碼有問題,或者我懷疑是錯誤的鉤子應用。有任何想法嗎?