Hello Christian,
You can copy the function but you need to rename it then because you can’t have two functions by the same name. However, you can also do this within one function, which makes it more organized. Here’s a rewritten example:
add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_add_note_based_on_product_id', 10, 2 );
function wpo_wcpdf_add_note_based_on_product_id ($template_type, $order) {
if ($template_type == 'invoice' ) {
// set notes for products
$product_notes = array(
array(
'note' => 'Note 1',
'product_ids' => array( 123, 456 ),
),
array(
'note' => 'Note 2',
'product_ids' => array( 234, 567 ),
),
);
// get list of product ids in the order
$product_ids = array();
$items = $order->get_items();
foreach ($items as $item_id => $item) {
$product_ids[] = (int) $item->get_product_id();
$product_ids[] = (int) $item->get_variation_id();
}
$product_ids = array_unique( $product_ids );
// show product notes when matches found
foreach ($product_notes as $product_note) {
if ( count( array_intersect( $product_ids, $product_note['product_ids'] ) ) > 0 ) {
printf('<p>%s</p>', $product_note['note']);
}
}
}
}
If you need more help with this I recommend that you look for a developer, as this is quite advanced and somewhat beyond what we can offer as part of free support, I hope you understand!