WooCommerce Get Order Product Details Before Payment in Plugin

前端 未结 2 1141
生来不讨喜
生来不讨喜 2020-12-17 02:42

I need to display order details from cart before payment in plugin.

I work on one plugin what connect woocommerce and an payment API and there I need to send array o

2条回答
  •  天涯浪人
    2020-12-17 03:05

    I think you are looking for woocommerce_checkout_process hook. WC_Checkout::process_checkout() – Process the checkout after the confirm order button is pressed.

    Here is the code:

    add_action('woocommerce_checkout_process', 'wh_getCartItemBeforePayment', 10);
    
    function wh_getCartItemBeforePayment()
    {
        $items = WC()->cart->get_cart();
    
        foreach ($items as $item => $values)
        {
            $_product = $values['data']->post;
            $product_title = $_product->post_title;
            $qty = $values['quantity'];
            $price = get_post_meta($values['product_id'], '_price', true);
        }
    }
    

    Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.

    Hope this helps!

提交回复
热议问题