微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – WC_Order get_items()及其数量

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

我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

我确实尝试挖掘抽象woo commerce文件夹中的电子邮件PHP文件,看看他们如何做,因为他们在电子邮件中发送数量,但有点丢失

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

通过研究,您还可以从订单商品中获取数量
$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 );

原文地址:https://www.jb51.cc/php/134675.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐