我想將一些woocommerce訂單數據處理爲單獨的數據庫。除了項目列表之外,一切都有效。如何在wordpress/woocommerce中處理訂單商品數組
add_action('woocommerce_payment_complete', 'handle_order_completed');
function handle_order_completed($order_id){
$order = wc_get_order($order_id);
$name = $order->billing_first_name . " " . $order->billing_last_name;
$billingEmail = $order->billing_email;
$billingPhone = $order->billing_phone;
$orderlink = $order->get_view_order_url();
$products = $order->get_items();
$orderMeta = get_post_meta($order_id, 'pass_type');
foreach($products as $prod){
$sql_insert = <<<SQL
INSERT INTO cards (cardnumber, name, phone, type, sku)
VALUES ("$cardnumber", "$name", "$billingPhone", "$type", "$prod['product_sku']")
SQL;
$prod['product_id'];
}
我需要知道什麼數組鍵$order->get_items()
但我無法找到任何地方的列表。我需要產品SKU,產品線總數以及添加到產品中的自定義字段。我需要使用自定義字段來決定如何將其他數據添加到數據庫。
請在此代碼中添加更多信息您試圖獲取/執行的操作。它不清楚。 – BenB
這些信息來自哪裏? –