【发布时间】:2016-09-07 19:13:55
【问题描述】:
我想知道是否有一个钩子可以在单击时更改“下单按钮”的行为。我正在尝试在下订单时更换/更改产品,因为产品选择(所有可用产品)也在结帐页面中。
到目前为止,我一直在尝试操纵woocommerce_checkout_order_review hook & 失败。
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
}
}
下订单时不会触发上述挂钩。也许我的代码有问题,或者我怀疑应用了错误的钩子。有什么想法吗?
【问题讨论】:
标签: wordpress woocommerce hook checkout orders