woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.33k stars 10.75k forks source link

Manual Orders for Bundled Products created with `WC_Order` Missing Child Line-Items #44118

Closed e2corporation closed 7 months ago

e2corporation commented 8 months ago

Prerequisites

Describe the bug

When creating a manual order programmatically with WC_Order for a Bundled Virtual Subscription Product, the line items are not added automatically, only the first product in the bundle are added. Additionally, when manually adding a child item to the order using WC_Order_Item_Product, there are no class methods to set any Bundling metadata one would expect to find on a normal order for a Bundled product created by either Checkout or Admin. The properties bundled_by or even bundled_items are not being preserved.

Observe the order workflow below, is this designed behavior to ignore the child items when the Bundled Product is added to the order sheet? Even if the Individual Line Items are added with WC_Order::add_product, there is no method to associate the product with a parent, or to set bundled by meta properties.

<?php
# Product Bundle (Example contains 5 child products, also virtual)
$digital_bundle = new WC_Product_Bundle(12345);

# New Order + Adding Bundle Product
$order = new WC_Order();
$order->set_customer_id(1);
$order->set_status('completed', 'Auto-Order of Bundled Virtual Product.');
$order->set_created_via('internal-api');
$order->add_product($digital_bundle, 1, array('subtotal' => 0, 'total' => 0)); 
$order->calculate_totals();
$order->save();

Expected behavior

The Order sheet's Line Items should contain all child products that belong to the Bundled Product being added, not just the root product of the Bundle.

Actual behavior

Only the Parent Bundled Product is added to the Order, none of the child items that belong to the Bundle.

Steps to reproduce

  1. Initiate a new Order with WC_Order or wc_create_order.
  2. Add a Product Bundle to the Order with WC_Order::add_product.
  3. Save The Order
  4. Observe that the Order Line Items do NOT contain bundled child products.

WordPress Environment

WordPress Environment

WordPress address (URL): < REDACTED > Site address (URL): < REDACTED > WC Version: 8.2.1 REST API Version: ✔ 8.2.1 WC Blocks Version: ✔ 11.1.2 Action Scheduler Version: ✔ 3.6.3 Log Directory Writable: ✔ WP Version: ❌ 6.3.2 - There is a newer version of WordPress available (6.4.2) WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: ✔ WP Cron: – Language: en_US External object cache: –

Server Environment

Server Info: Apache PHP Version: 8.2.13 PHP Post Max Size: 100 MB PHP Time Limit: 3600 PHP Max Input Vars: 10000 cURL Version: 7.88.1 OpenSSL/3.0.11

SUHOSIN Installed: – MySQL Version: 8.0.35-27 Max Upload Size: 50 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 8.2.1 WC Database Prefix: wp_ Total Database Size: 72.22MB Database Data Size: 48.88MB Database Index Size: 23.34MB wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.06MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 2.17MB + Index: 1.23MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 1.52MB + Index: 1.13MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 1.52MB + Index: 0.59MB + Engine InnoDB wp_aioseo_cache: Data: 0.11MB + Index: 0.03MB + Engine InnoDB wp_aioseo_notifications: Data: 0.09MB + Index: 0.06MB + Engine InnoDB wp_aioseo_posts: Data: 2.52MB + Index: 0.13MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.06MB + Index: 0.09MB + Engine InnoDB wp_e_events: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_eg_grids: Data: 0.13MB + Index: 0.02MB + Engine InnoDB wp_eg_item_elements: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_eg_item_skins: Data: 1.52MB + Index: 0.03MB + Engine InnoDB wp_eg_navigation_skins: Data: 1.52MB + Index: 0.02MB + Engine InnoDB wp_integrate_google_drive_files: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_integrate_google_drive_logs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_integrate_google_drive_shortcodes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mvx_cust_answers: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mvx_cust_questions: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mvx_products_map: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mvx_shipping_zone_locations: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mvx_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mvx_vendor_ledger: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_mvx_vendor_orders: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mvx_visitors_stats: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_options: Data: 5.39MB + Index: 0.17MB + Engine InnoDB wp_pmpro_discount_codes: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_pmpro_discount_codes_levels: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_pmpro_discount_codes_uses: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_pmpro_membership_levelmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_pmpro_membership_levels: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_pmpro_membership_ordermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_pmpro_membership_orders: Data: 0.02MB + Index: 0.20MB + Engine InnoDB wp_pmpro_memberships_categories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_pmpro_memberships_pages: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_pmpro_memberships_users: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_postmeta: Data: 16.48MB + Index: 10.42MB + Engine InnoDB wp_posts: Data: 3.23MB + Index: 0.81MB + Engine InnoDB wp_ppress_coupons: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_ppress_customers: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_ppress_forms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_ppress_formsmeta: Data: 0.06MB + Index: 0.05MB + Engine InnoDB wp_ppress_meta_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_ppress_ordermeta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_ppress_orders: Data: 0.02MB + Index: 0.13MB + Engine InnoDB wp_ppress_plans: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_ppress_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_ppress_subscriptions: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_term_relationships: Data: 7.52MB + Index: 4.52MB + Engine InnoDB wp_term_taxonomy: Data: 0.20MB + Index: 0.22MB + Engine InnoDB wp_termmeta: Data: 0.20MB + Index: 0.22MB + Engine InnoDB wp_terms: Data: 0.16MB + Index: 0.16MB + Engine InnoDB wp_um_metadata: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_usermeta: Data: 0.09MB + Index: 0.06MB + Engine InnoDB wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_bundle_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_order_composite_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_operational_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_wc_orders_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.22MB + Index: 0.44MB + Engine InnoDB wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcfm_daily_analysis: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcfm_detailed_analysis: Data: 0.05MB + Index: 0.00MB + Engine InnoDB wp_wcfm_enquiries: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_enquiries_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_enquiries_response: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_enquiries_response_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_fbc_chat_rows: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_fbc_chat_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcfm_fbc_chat_visitors: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_fbc_offline_messages: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_following_followers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_orders: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcfm_marketplace_orders_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_product_multivendor: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wcfm_marketplace_refund_request: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_refund_request_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_reverse_withdrawal: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_reverse_withdrawal_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_review_rating_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_reviews: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_reviews_response: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_reviews_response_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_shipping_zone_locations: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_store_taxonomies: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_vendor_ledger: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_withdraw_request: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_marketplace_withdraw_request_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_messages: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_messages_modifier: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_messages_stat: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_support: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_support_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_support_response: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wcfm_support_response_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfu_dbxqueue: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfu_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfu_userdata: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woobe_history: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_woobe_history_bulk: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_bundled_itemmeta: Data: 0.09MB + Index: 0.09MB + Engine InnoDB wp_woocommerce_bundled_items: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wpforms_payment_meta: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wpforms_payments: Data: 0.02MB + Index: 0.14MB + Engine InnoDB wp_wpforms_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_debug_events: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yith_wcwl: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_yith_wcwl_lists: Data: 0.02MB + Index: 0.03MB + Engine InnoDB

Isolating the problem

e2corporation commented 7 months ago

@lanej0 Hello Jonathan -- are there other WooCommerce Users experiencing this issue? Does WooCommerce have documentation on WC_Order with respect to Product Bundles? This seems like essential functionality that should be working, it would be great to have official documentation on programmatically ordering virtual bundle. Thank you.

jorgeatorres commented 7 months ago

Hi @e2corporation!

This seems to be about the WooCommerce Product Bundles plugin, not WooCommerce core. We suggest you contact support so that they can forward your question to this extension devs and keep you in the loop.

Even if in the end some changes are needed in core, we can't answer for what those would look like, given that's a different extension.

Based on that I'm going to close this issue, but please re-open if I missed or misinterpreted something.

e2corporation commented 7 months ago

Thank you Jorge, since this is apart of the woocommerce ecosystem why not transfer the ticket?

On Thu, Feb 1, 2024 at 6:06 AM, Jorge A. Torres @.***(mailto:On Thu, Feb 1, 2024 at 6:06 AM, Jorge A. Torres < wrote:

Closed #44118 as not planned.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

jorgeatorres commented 7 months ago

@e2corporation: That's a fair question. Sadly, the Product Bundles repository is private, and so transferring this issue would mean you lose visibility by not being able to follow the conversation. If you go the support way you'll be able to be notified when the Product Bundles devs reply.