• Resolved matshop

    (@matshop)


    I want a trigger action when order is placed, in order to fetch order data.
    i used this action :
    add_action( ‘woocommerce_new_order’, ‘myfunction’, 1, 1 );
    function myfunction( $order_id ) {
    $order = new WC_Order( $order_id );
    $items = $order->get_items();
    foreach ( $order->get_items() as $item_key => $item ) {

    $product = $order->get_product_from_item( $item );

    $sku3 = $product->get_sku();

    // print_r( $item );
    }

    but doesen’t fetch product detail, only customer details are visable.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    Please try the below code

    add_action( ‘woocommerce_new_order’, ‘myfunction’, 1, 1 );
    function myfunction( $order_id ) {
        $order = new WC_Order( $order_id );
        $items = $order->get_items();
        foreach ( $order->get_items() as $item_key => $item ) {
            $product = $item->get_product(); // the WC_Product object
            $product_type = $product->get_type();
            $product_sku = $product->get_sku();
            $product_price = wc_price($product->get_price());
            $stock_quantity = $product->get_stock_quantity();
        }
    }

    you can find product more information in $product object.

    please check the below link for more product information

    https://magemeta.com/2018/10/19/woocommerce-get-order-details-by-order-id/

    Thanks

    Plugin Support Tseten a11n

    (@tibetanitech)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘trigger when order placed’ is closed to new replies.