我有6个主要类别的产品。 我要根据购物车中产品的类别修改订单号。它需要选择购物车中出现的第一个产品的类别。基于此类别,我想添加以下功能:
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );
function change_woocommerce_order_number( $order_id ) {
$prefix = 'AB-';
$new_order_id = $prefix . $order_id;
return $new_order_id;
}
因此,基本上,我想在此函数中创建if else语句,例如:
if ('category of first product in appearing in cart' === 'category id / category name') {
$prefix = 'AB-';
$new_order_id = $prefix . $order_id;
return $new_order_id;
}
elseif ('category of first product in appearing in cart' === 'category id / category name') {
$prefix = 'CD-';
$new_order_id = $prefix . $order_id;
return $new_order_id;
}
elseif ('category of first product in appearing in cart' === 'category id / category name') {
$prefix = 'EF-';
$new_order_id = $prefix . $order_id;
return $new_order_id;
}
现在的问题是,我需要获取购物车中出现的第一个产品的类别ID /类别名称。如何在我的functions.php文件中得到它?