❌

Reading view

Declaring parent-child cart item relationships in WooCommerce 11.3

In WooCommerce 11.3, the “N in cart” count of the Product Button block (including the button inside Add to Cart with Options) will leave out cart items that an extension declares as children of another cart item.

Until now, a product that was in the cart only as part of another item, like a product inside a bundle, made its button say “1 in cart”, even though the shopper never added it on its own. Core can’t tell those items apart from the ones added separately, so the extension that adds them needs to say which item they belong to.

To do that, there’s a new filter, woocommerce_store_api_cart_item_parent_item_key, and a new read-only field in Store API cart items, parent_item_key (a string, or null by default).

A few details:

  • WooCommerce never marks an item as a child by itself. Only your extension does.
  • The parent key is returned only while the parent item is in the cart. If the shopper removes the parent, or it’s dropped from the cart, the child’s parent_item_key becomes null and it counts as a standalone item again.
  • If the filter returns a key that doesn’t match an item in the cart, or the item’s own key, WooCommerce returns null.
  • If a product appears in several cart lines, the count now adds them all up (before, the hydrated button showed only the first line’s quantity).

For now, the Product Button count is the only place that uses parent_item_key, but the idea is that blocks can rely on it whenever they need to know that an item belongs to another one. For example, in the future the Cart and Mini-Cart blocks could show child items indented under their parent item. So even if the “N in cart” count isn’t a problem for your extension, we think it’s worth declaring the parent of the items your extension adds.

How can developers tell if they are affected?

You’re affected if your extension adds cart items on behalf of another cart item. For example bundles, composite products, mix and match, force sells, chained products or “frequently bought together”.

An easy way to check is to add the parent product to the cart and look at the Product Button of one of the products it added. If it says “1 in cart”, your extension should use the new filter.

Free gift or upsell plugins that add a real product tied to another item can decide either way, because “1 in cart” may be correct for them.

Nothing breaks if you don’t adopt the filter. Those items just keep counting as they do today.

What action do developers need to take if affected?

Store the parent’s cart item key (the one WC()->cart->add_to_cart() returns, not a product ID) in the child’s cart item data, and return it from the filter:

add_filter(
	'woocommerce_store_api_cart_item_parent_item_key',
	function ( $parent_item_key, $cart_item ) {
		return $cart_item['_my_extension_parent_item_key'] ?? $parent_item_key;
	},
	10,
	2
);

For any other item, return $parent_item_key unchanged so you don’t erase a parent declared by another extension. You don’t need to clear the stored key when the parent leaves the cart, WooCommerce handles that.

The Store API documentation has a full example, including how to add the parent and the child.

The post Declaring parent-child cart item relationships in WooCommerce 11.3 appeared first on The WooCommerce Developer Blog.

Drag and Drop Grid Building in the WordPress Editor (First Look)

💾

A first look at drag-and-drop grid building in the WordPress editor, running inside my Create Not Learn prototype.

Try it in WordPress Playground!

https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/getdave/create-not-learn-editor/refs/playground/getdave/gutenberg-pr-84894-grid/blueprint.json

Andrei Draganescu has been building a free-form grid for Gutenberg. You can drag, resize, snap and rotate blocks on a manual grid in a way that's never been possible in WordPress before.

Create Not Learn is built on WordPress packages, so anything that lands in Gutenberg I can pull straight in. I wanted to see how Andrei's work feels in a real page-building flow.

It's still a work in progress. I'd love the grid to be more visible while you drag and resize, so you can tell when a block is about to snap. Kudos to Andrei for the work so far.

Want to try it? Open the Playground demo below and follow Grid layouts in the site's menu. Switch to Edit, pick a section, then choose Edit design and More control. The grid controls only work on the Grid layouts page.

🔗 Links

- Try it in WordPress Playground: https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/getdave/create-not-learn-editor/refs/playground/getdave/gutenberg-pr-84894-grid/blueprint.json

- Create Not Learn on GitHub: https://github.com/getdave/create-not-learn-editor

- The grid demo PR on Create Not Learn: https://github.com/getdave/create-not-learn-editor/pull/161

- Try it in WordPress Playground: https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/getdave/create-not-learn-editor/refs/playground/getdave/gutenberg-pr-84894-grid/blueprint.json

- Andrei's grid canvas issue: https://github.com/WordPress/gutenberg/issues/85505

- The Gutenberg PR this demo pulls in: https://github.com/WordPress/gutenberg/pull/85210


⏰ Chapters
00:00 Intro
00:31 The Create Not Learn editor
01:13 Opening the Grid layouts page
01:42 Edit design
02:01 More control
02:17 Moving and resizing blocks on the grid
03:17 Rotating blocks
03:22 How to try it yourself

Is this THE END of the WORDPRESS block toolbar?

💾

Try it in Playground: https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/getdave/create-not-learn-editor/trunk/demos/blueprint.json

Github repo: https://github.com/getdave/create-not-learn-editor

-----

The WordPress block toolbar is becoming too cluttered. I am demonstrating a new approach to consolidate these tools for a better editing experience.

Jay Costa has identified that the current block toolbar is no longer fit for purpose, often feeling unwieldy for everyday tasks. This video explores how consolidating these interface elements can improve consistency and speed up your workflow within the editor.

By streamlining the layout, we can reduce friction and create a more intuitive environment for managing content. I walk through the specific formatting adjustments that help simplify the block toolbar while keeping the power of the system intact.

Subscribe for weekly WordPress editor breakdowns, and share your thoughts on whether these interface changes would improve your daily workflow.
❌