I need to add to the attachment of the confirmation mail after successful checkout static pdf attachment, but changing the source route of the file based on language he chose on my website. I use this code to attach the static pdf to the attachment:
add_filter( 'woocommerce_email_attachments', 'wphelp_email_files_woo', 10, 4 );
function wphelp_email_files_woo( $attachments, $email_id, $order, $email ) {
$email_ids = array( 'new_order', 'customer_processing_order' );
if ( in_array ( $email_id, $email_ids ) ) {
$upload_dir = wp_upload_dir();
$attachments[] = $upload_dir['basedir'] . "/2021/12/FORMULAR_NA_ODSTUPENIE_OD_ZMLUVY-1.pdf"; //Change the route and name for yours
}
return $attachments;
}
CodePudding user response:
Use get_locale()
for get the website locale.
if (get_locale() == 'en_GB'){
$attachments[] = $upload_dir['basedir'] . "/2021/12/FORMULAR_NA_ODSTUPENIE_OD_ZMLUVY-1.pdf";
}
else {
$attachments[] = $upload_dir['basedir'] . "/2021/12/otherfile.pdf";
}