Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delete custom order item meta data from WC_Subscription object #585

Open
Johnny99211 opened this issue Mar 25, 2024 · 0 comments
Labels
type: bug The issue is a confirmed bug.

Comments

@Johnny99211
Copy link

Johnny99211 commented Mar 25, 2024

Describe the bug

I am facing a massive issue which is only facing inside a subscription order. When reproducing this issue inside a normal WooCommerce order, everything works as expected.

As a plugin developer, I'm always trying to make good compatibility. In my case, my plugin sets a custom meta to a WooCommerce order or subscription, depending on if it's a normal order or subscription:

add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'woocommerce_checkout_create_order_line_item_action' ), 10, 4 );
public function woocommerce_checkout_create_order_line_item_action( WC_Order_Item_Product $order_item, string $cart_item_key, array $values, WC_Order $order ): void {
	if ( ! empty( $values['elm_license_id'] ) ) {
		$order_item->add_meta_data( '_elm_license_id', $values['elm_license_id'] );
	}
}

This works as expected and documented inside the WooCommerce developer documentation:

image

When I now press the “Assign license” button (which just triggers the form submit with an additional hidden field), a script runs within the following hook which does some things. At the end, the custom meta should be deleted. This works fine inside any normal order, but inside a subscription, nothing happens. The meta is still there (normal posts table and HPOS). It was working before the version 6.0.0 but since the update, I'm no longer able to delete any custom meta:

add_action( 'woocommerce_update_order', array( $this, 'woocommerce_update_order_action' ), 99, 3 );
public function woocommerce_update_order_action( int $order_id, WC_Order $order ): void {
	foreach ( $order->get_items() as $order_item ) {
		$order_item->delete_meta_data( '_elm_license_id' );
		$order_item->save();
	}
}

To Reproduce

  1. Use the above hooks to set a custom meta when creating an order / subscription
  2. Use the 2nd snippet to delete the meta again when pressing the “Update” button inside a subscription

Expected behavior

The custom meta should be gone.

Actual behavior

The custom meta is still there.

Product impact

  • [yes ] Does this issue affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
  • [no] Does this issue affect WooCommerce Payments? yes/no/tbc, add issue ref
@Johnny99211 Johnny99211 added the type: bug The issue is a confirmed bug. label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

1 participant