Automattic\WooCommerce\Internal\Utilities

COTMigrationUtil::get_post_or_order_id()publicWC 1.0

Helper function to get ID from a post or order object.

Method of the class: COTMigrationUtil{}

No Hooks.

Return

Int. Order or post ID.

Usage

$COTMigrationUtil = new COTMigrationUtil();
$COTMigrationUtil->get_post_or_order_id( $post_or_order_object ) : int;
$post_or_order_object(WP_Post/WC_Order) (required)
WP_Post/WC_Order object to get ID for.

COTMigrationUtil::get_post_or_order_id() code WC 8.7.0

public function get_post_or_order_id( $post_or_order_object ) : int {
	if ( is_numeric( $post_or_order_object ) ) {
		return (int) $post_or_order_object;
	} elseif ( $post_or_order_object instanceof WC_Order ) {
		return $post_or_order_object->get_id();
	} elseif ( $post_or_order_object instanceof WP_Post ) {
		return $post_or_order_object->ID;
	}
	return 0;
}