ulc_send_csv_as_download_link
Filters whether to send the CSV as a download link when an email is processed in WooCommerce.
add_filter( 'ulc_send_csv_as_download_link', $callback, 10, 2 );
Description
Filters the CSV file download link for WooCommerce emails. Allows developers to modify or conditionally prevent the CSV attachment based on the email ID and order object. Useful for customizing order notifications with specific data.
Usage
add_filter( 'ulc_send_csv_as_download_link', 'your_function_name', 10, 2 );
Parameters
-
$email_id(mixed) - This parameter represents the existing attachments to the email.
-
$order(mixed) - This parameter contains the ID of the email being sent, which can be used to conditionally modify the behavior of the hook.
Return Value
The filtered value.
Examples
// Example callback function to modify the CSV download link for WooCommerce emails.
// This function demonstrates how to conditionally include or exclude the CSV download
// based on specific order details or email types.
function my_custom_csv_download_filter( $should_send_csv, $email_id, $order ) {
// If the email is for a completed order and the order total is less than $100,
// we don't want to send the CSV.
if ( 'customer_completed_order' === $email_id && $order->get_total() < 100 ) {
return false; // Do not send the CSV attachment.
}
// Otherwise, we allow the default behavior or other filters to determine if the CSV is sent.
// If $should_send_csv was already true from a previous filter, it will remain true.
return $should_send_csv;
}
add_filter( 'ulc_send_csv_as_download_link', 'my_custom_csv_download_filter', 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/integrations/woocommerce/class-woo-automator-codes.php:525
src/classes/integrations/woocommerce/class-woo-automator-codes.php:725
public function attach_to_wc_emails( $attachments, $email_id, $order ) {
// Is valid WC Order?
if ( ! $order instanceof WC_Order ) {
return $attachments; //bailout.
}
$order_id = $order->get_id();
$order_codes = Database::get_codes_usage_by_order_id( $order_id );
// Make sure to only add attachments if the order has codes
if ( empty( $order_codes ) ) {
return $attachments;
}
if ( ( 'customer_processing_order' === $email_id || 'customer_completed_order' === $email_id ) &&
false === apply_filters( 'ulc_send_csv_as_download_link', false, $email_id, $order )
) {
$attachments = array_merge( $attachments, $this->generate_csv( $order->get_id() ) );
}
return $attachments;
}