Get product SKU by product ID in WooCommerce

/**
 * Gets product SKU by product ID in WooCommerce.
 *
 * @see https://wpcodebook.com/snippets/get-product-sku-by-product-id-in-woocommerce/
 */
function wpcodebook_get_product_sku( $product_id ) {
	return ( ( $product = wc_get_product( $product_id ) ) ? $product->get_sku() : false );
}

Leave a Comment