2016-05-12 11 views
0

クリックするとPlace Order Buttonの動作を変更するためのフックがあるのだろうかと思います。私は、製品選択(すべての利用可能な製品)がCheckoutページにもあるため、注文時に製品を交換/変更しようとしています。Place注文のカスタム動作のための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 
    } 
} 

上記のフックは、Place Orderでトリガされません。おそらく、私のコードに何か問題があるかもしれません。あるいは、間違ったフックが適用されていると思われるかもしれません。何か案は?より詳細な説明については

答えて

0

ネヴァーマインド...答えを見つけた...

add_action('woocommerce_checkout_process', 'change_product_upon_submission'); 
function change_product_upon_submission() { 
    if (!empty($_POST['_wpnonce']) && !empty($_POST['selectedproductid'])) { 
    $selectedproduct = $_POST['selectedproductid']; // Get the selected product 
    WC()->cart->empty_cart(); //Empty the cart 
    WC()->cart->add_to_cart($selectedproduct); // Insert the selected product in the cart 
    } 
} 

Woocommerce Replace Product in Cart Upon Place Order in Checkout Page

を見ます
関連する問題