Sync a custom product attribute with an invoice item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'storeabill_woo_order_item_line_item_sync_props', 'my_child_sync_line_item_props', 10, 3 ); | |
/** | |
* @param $props | |
* @param \Vendidero\StoreaBill\WooCommerce\OrderItemProduct $item | |
* @param $args | |
* | |
* @return mixed | |
*/ | |
function my_child_sync_line_item_props( $props, $item, $args ) { | |
if ( $order_item = $item->get_order_item() ) { | |
if ( $product = $order_item->get_product() ) { | |
$attribute_key = 'marke'; | |
$attribute_label = 'Marke'; | |
if ( $attribute_value = $product->get_attribute( $attribute_key ) ) { | |
$props['attributes'][] = new \Vendidero\StoreaBill\Document\Attribute( array( | |
'key' => $attribute_key, | |
'value' => $attribute_value, | |
'label' => $attribute_label | |
) ); | |
} elseif ( $product->get_parent_id() > 0 ) { | |
/* | |
* In case the product is a child product - lets check the parent product | |
* for the attribute data in case it was not found for the child. | |
*/ | |
if ( $parent = wc_get_product( $product->get_parent_id() ) ) { | |
if ( $attribute_value = $parent->get_attribute( $attribute_key ) ) { | |
$props['attributes'][] = new \Vendidero\StoreaBill\Document\Attribute( array( | |
'key' => $attribute_key, | |
'value' => $attribute_value, | |
'label' => $attribute_label | |
) ); | |
} | |
} | |
} | |
} | |
} | |
return $props; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment