Trying to change order author ID by custom cart_item_data
-
Hi,
In my woocommerce, products can be sold by multiples sellers.
All product have the same author id (Admin)
I use woocommerce_before_add_to_cart_button and woocommerce_add_cart_item_data
to save the needed ID “pharmacie_id”add_action( 'woocommerce_before_add_to_cart_button', 'pharmizz_hidden_pharmaid' ); function pharmizz_hidden_pharmaid() { $pharmacie_id = urldecode($_GET['pharmacie_id']); ?> <input type="hidden" id="pharmacieid_val" name="pharmacie_id" value="<? echo $pharmacie_id ?>"> <?php } add_filter( 'woocommerce_add_cart_item_data', 'pharmizz_add_cart_item_data', 10, 2 ); function pharmizz_add_cart_item_data( $cart_item_data, $product_id ) { $cart_item_data['pharmacie_id'] = $_REQUEST['pharmacie_id']; if($_GET['pharmacie_id'] == "") { $cart_item_data['pharmacie_id'] = $_REQUEST['data-pharmacie-id']; } return $cart_item_data; } Now I need to change the product author by the saved Id (pharmacie_id) I tried to use woocommerce_checkout_create_order_line_item like this
add_action( ‘woocommerce_checkout_create_order_line_item’, ‘parmizz_add_pharmaid_to_order_items’, 10, 4 );
function parmizz_add_pharmaid_to_order_items( $item, $cart_item_key, $values, $order ) {
//$values[‘author_id’] = $item[‘pharmacie_id’];
//$item->add_meta_data(‘author’, $values[‘pharmacie_id’] );if ( empty( $values[‘pharmacie_id’] ) ) {
return;
}
$item->add_meta_data(‘author_id’, $values[‘pharmacie_id’] );
}But not work, How can I manage this ?
Best,
- The topic ‘Trying to change order author ID by custom cart_item_data’ is closed to new replies.