Answer the question
In order to leave comments, you need to log in
Why is cart content not being passed in Woocommerce?
I want to pull out the data from the shopping cart to send it to CRM, but I check it by email and the Name and Phone number come, but I can’t get the contents of the cart... Please tell me where can there be an error?
add_action( 'woocommerce_new_order', 'sender_for_wc_order' );
function sender_for_wc_order($order_id) {
$order = wc_get_order( $order_id);
$data = $order->get_data(); // данные заказа
$user_name = $data['billing']['first_name'];
$user_phone = $data['billing']['phone'];
$order_items = $order->get_items();
foreach( $order_items as $item_id => $item ){
$item_id = $item->get_id();
$item_name = $item->get_name();
$item_type = $item->get_type();
$product_id = $item->get_product_id();
$wc_product = $item->get_product();
$item_data = $item->get_data();
$info .= $item_data['name'];
$info .= $item_data['product_id'];
$info .= $item_data['variation_id'];
$info .= $item_data['quantity'];
$info .= $item_data['tax_class'];
$info .= $item_data['subtotal'];
$info .= $item_data['subtotal_tax'];
$info .= $item_data['total'];
$info .= $item_data['total_tax'];
}
mail('[email protected]', 'test', 'Имя: '.$user_name.' | Телефон: '.$user_phone.' | Details: '.$info);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question