Automattic\WooCommerce\Internal\Utilities

COTMigrationUtil::get_post_or_order_id()publicWC 1.0

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

Метод класса: COTMigrationUtil{}

Хуков нет.

Возвращает

int. Order or post ID.

Использование

$COTMigrationUtil = new COTMigrationUtil();
$COTMigrationUtil->get_post_or_order_id( $post_or_order_object ) : int;
$post_or_order_object(WP_Post/WC_Order) (обязательный)
WP_Post/WC_Order object to get ID for.

Код COTMigrationUtil::get_post_or_order_id() 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;
}