WC_Order get_items()及其数量

时间:2015-05-13 12:13:48

标签: php woocommerce

我正在尝试构建一个应用程序,它将我的商业订单,订单商品和数量,

发送给我

我90%在那里,

function custom_woocommerce_complete_order_sms( $order_id ) {
        global $woocommerce;
        if ( !$order_id )
        return;
        $order = new WC_Order( $order_id );

        $product_list = '';
        $order_item = $order->get_items();

        foreach( $order_item as $product ) {
            $prodct_name[] = $product['name']; 
        }

        $product_list = implode( ',\n', $prodct_name );






    require "twilio-php-master/Services/Twilio.php";


    $AccountSid = "xxxxxxxxx";
    $AuthToken = "xxxxxxxxx";

    $client = new Services_Twilio($AccountSid, $AuthToken);


    $people = array(
        "xxxxxxxxxx" => "Me",
    );


    foreach ($people as $number => $name) {

        $sms = $client->account->messages->sendMessage(



            "+44xxxxxxxxxx", 

            // the number we are sending to - Any phone number
            $number,

            // the sms body
            "Hey $name, there is a new Order, the order is, $product_list"
        );


    }

    }

我的问题是我不知道如何获取物品数量,例如我的文字看起来像列表,第1项,第2项,第3项,我希望它说项目1 x1,项目2 x2,项目3 x3 < / p>

我确实尝试深入了解抽象woo commerce文件夹中的电子邮件php文件,看看他们如何在电子邮件中发送数量但有点丢失

同样在WC_Abstract_Order类中我唯一可以找到的是get_item_total,它返回所有项目的总和

1 个答案:

答案 0 :(得分:14)

通过研究,您还可以从订单商品中获取数量

 $product['qty'];

因此,循环并将数量添加到项目名称(下方)

很简单
$product_details = array();
$order_items = $order->get_items();
foreach( $order_items as $product ) {
                $product_details[] = $product['name']."x".$product['qty'];

            }

            $product_list = implode( ',', $product_details );
相关问题