Several of our WooCommerce development clients have complex bespoke layouts on their product pages, integrated using Advanced Custom Fields with a rigid set of additional fields that are then output within WooCommerce templates. While ACF offers some freedom to developers and clients alike, it limits any future content additions to the set of fields initialised on first setup – or requires further development to add field calls to template files.
To give clients and our SEO team the flexibility to improve and extend product pages without needing the input of a developer we wanted to implement the Gutenberg editor on WooCommerce products, but without breaking older legacy ACF-editable products that might not need updating yet.
The process was slightly complicated by the need to hook into WordPress early enough to actually change the editor presented to the user, but not before certain information was set up for us (namely current_screen
and the post
object). Ultimately we couldn’t find a hook that offered both those options, so we reverted to hooking into admin_init
and ran checks on data available in the query string instead. Ideal? No. But it is what it is…
To see or download our plugin that conditionally allows Gutenberg on WooCommerce products, please visit the official repo on Github.
Lead photo by Ben Griffiths