doulan1866 2019-02-21 09:01
浏览 32

如何获得订单数据woocommerce? [重复]

This question already has an answer here:

i use this sourse code. This code dont work, why ? Telegram API and chat_id is correct.

add_action( 'woocommerce_new_order', 'send_massage_to_telegram',  1, 1  );
function send_massage_to_telegram ($order_id) {

    $order = wc_get_order($order_id);

// Iterating through each WC_Order_Item_Product objects
    foreach ($order->get_items() as $item_key => $item_values) {

        ## Using WC_Order_Item methods ##

        // Item ID is directly accessible from the $item_key in the foreach loop or
        $item_id = $item_values->get_id();


        ## Using WC_Order_Item_Product methods ##
        $item_name = $item_values->get_name(); // Name of the product
        $item_type = $item_values->get_type(); // Type of the order item ("line_item")

        $product_id = $item_values->get_product_id(); // the Product id
        $product = $item_values->get_product(); // the WC_Product object

        ## Access Order Items data properties (in an array of values) ##
        $item_data = $item_values->get_data();

        $product_name = $item_data['name'];
        $product_id = $item_data['product_id'];
        $variation_id = $item_data['variation_id'];
        $quantity = $item_data['quantity'];
        $tax_class = $item_data['tax_class'];
        $line_subtotal = $item_data['subtotal'];
        $line_subtotal_tax = $item_data['subtotal_tax'];
        $line_total = $item_data['total'];
        $line_total_tax = $item_data['total_tax'];
        $item_total = $item_data->get_total();

        // Get data from The WC_product object using methods (examples)
        $product_type = $product->get_type();
        $product_sku = $product->get_sku();
        $product_price = $product->get_price();
        $stock_quantity = $product->get_stock_quantity();


    }

     $sendToTelegram = fopen("https://api.telegram.org/bot:xxxxxxxxxxxxxxxxx/sendMessage?chat_id=00000000000&parse_mode=html&text={$product_price}", "r");
}
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等