Skip to content

making other WC Order types (other than subscription) compatible with HPOS and custom fields#295

Merged
cbravobernal merged 4 commits intoWordPress:trunkfrom
trajche:trunk
Dec 29, 2025
Merged

making other WC Order types (other than subscription) compatible with HPOS and custom fields#295
cbravobernal merged 4 commits intoWordPress:trunkfrom
trajche:trunk

Conversation

@trajche
Copy link
Contributor

@trajche trajche commented Dec 20, 2025

Currently, other WC Order types than Subscription are not compatible (they don't show up in the edit page) with SCF and HPOS even though they show up in the field group rules when creating them. This PR fixes that.

@github-actions
Copy link

github-actions bot commented Dec 20, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props trajche.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@trajche
Copy link
Contributor Author

trajche commented Dec 20, 2025

In order to test you would have to create a custom WC order type and then enable HPOS. By default, it will allow you to select the custom WC order type from the SCF Field Groups but it will not show the meta boxes in the custom WC order view.

Here is sample code to register a WC order type called "Charges".

wc_register_order_type(
	'shop_order_charge',
	array(
		'label'                            => __( 'Charges', 'woocommerce' ),
		'capability_type'                  => 'shop_order',
		'public'                           => true,
		'hierarchical'                     => true,
		'exclude_from_orders_screen'       => false,
		'add_order_meta_boxes'             => true,
		'exclude_from_order_count'         => true,
		'exclude_from_order_views'         => false,
		'exclude_from_order_reports'       => false,
		'exclude_from_order_sales_reports' => false,
		'class_name'                       => 'WC_Order_Charge',
		'supports'                         => array( 'title' ),
		'rewrite'                          => true,
	)
);

And the Class would be something simple:

class WC_Order_Charge extends WC_Order {

	protected $object_type = 'order_charge';

	public function get_type() {
		return 'shop_order_charge';
	}
}

@cbravobernal cbravobernal self-requested a review December 29, 2025 16:44
Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

LGTM, I will merge it and then update the @ since to 6.7.2.

Next time please use a branch! It will make editions much easier.

@cbravobernal cbravobernal merged commit ca30915 into WordPress:trunk Dec 29, 2025
8 checks passed
@cbravobernal cbravobernal added this to the 6.8.0 milestone Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants