Custom file name (product category + order number) for PDF attachments
-
I’m trying to figure out how to create a custom file name for the PDF attachments. It needs to have the category name and the order number. For example: “Alemlube-00029.pdf”
Wrote a custom function for it but the plugin doesn’t seem to recognize my code.
Code:
add_filter( 'wpo_wcpdf_filename', 'wpo_wcpdf_custom_filename', 10, 4 ); function wpo_wcpdf_custom_filename( $filename, $template_type, $order_ids, $context ) { $count = count($order_ids); if ( $count == 1 && $template_type == 'invoice') { $order = wc_get_order($order_ids[0]); $items = $order->get_order_items(); foreach( $items as $item_id => $item ){ $terms = get_the_terms ( $item['product_id'], 'product_cat' ); $supplier_name = sanitize_title( $terms[0]->name); } # change the filename $filename = $supplier_name.'-'.$order->get_order_number().'.pdf'; } return $filename; }
Thoughts?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom file name (product category + order number) for PDF attachments’ is closed to new replies.