发送变体选项以条纹作为元数据与WooCommerce



我使用此代码将产品数据作为元数据发送到条带。

function filter_wc_stripe_payment_metadata( $metadata, $order, $source ) {
$count = 1;
foreach( $order->get_items() as $item_id => $line_item ){
$item_data = $line_item->get_data();
$product = $line_item->get_product();
$location = $product->get_attribute('location');
$product_name = $product->get_name();
$item_quantity = $line_item->get_quantity();
$item_total = $line_item->get_total();
$metadata['Item '.$count] = '';
$count += 1;
}
return $metadata;
}
add_filter( 'wc_stripe_payment_metadata', 'filter_wc_stripe_payment_metadata', 10, 3 );

如何获取产品的选定变体并将其添加到元数据中?

由于某种原因,$attribute = $product->get_attribute('location');对我不起作用。所以我使用了到目前为止效果很好的这个。

foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
$value = $args['autop'] ? wp_kses_post( $meta->display_value ) : wp_kses_post( make_clickable( trim( $meta->display_value ) ) );
$strings[] = $value;
}
$attribute = $strings[1];
$attribute = str_ireplace('<p>','',$attribute);
$attribute = str_ireplace('</p>','',$attribute);  
$metadata['Location'] = $attribute;

最新更新