在收到付款后,使用woocommerce挂钩检索销售信息。我可以找到产品名称,它实际上是一个订阅,但是我需要检索客户选择的订阅变体。我可以得到变化的列表,但不能找到确切的变化。
一切正常,除了能够发现客户选择的变化之外,
我什至试图获取元数据,只是为了无法访问它。
$meta_data = $product->get_formatted_meta_data('_', true);
foreach( $items as $item_id => $product )
{
$ProductName = $product->get_name(); // readable name of
product
$ProductId = $product->get_product_id(); // woocommerce id of
product
$PaymentAmount = $product->get_total(); // Get Payment of subscription item,
$ProductIndex = wc_get_product($ProductId);
if(! WC_Subscriptions_Product::is_subscription( $ProductIndex ) )
continue;
if(!$product->is_type( 'simple' ))
{
// THIS CRASHES WITH INTERNAL SERVICE ERROR
$variation_attributes = $product->get_variation_attributes();
foreach($variation_attributes as $attribute_taxonomy => $term_slug)
{
$taxonomy = str_replace('attribute_', '', $attribute_taxonomy );
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
$BusinessSpeciality = get_term_by( 'slug', $term_slug, $taxonomy )->name;
}
}
答案 0 :(得分:0)
找到了解决方案..简单:
foreach( $items as $item_id => $product )
{
if(!$product->is_type( 'simple' ) && $product->is_virtual())
{
$variation_id = $product['variation_id'];
$variation = new WC_Product_Variation($variation_id);
$BusinessSpeciality = current($variation->get_variation_attributes());
}
else
$BusinessSpeciality = 'Default';
}`