Slack developer reference

Filters for changing what each Slack for WooCommerce notification says.

Beka Rice Avatar

Written by

Last updated


Slack for WooCommerce lets developers change what each notification says with WordPress filters. Add them in a custom plugin or your theme’s functions.php. These filters apply to the settings screen under WooCommerce » Slack; stores still on the 1.x connection run older code (see the note at the end).

Customizations aren’t covered by support. If you need help with code, work with a WordPress developer.

Message filters

Each event’s message passes through a filter after its merge tags are filled in. The value is the message text in Slack’s formatting, so links use <url|text>.

EventFilterArguments
New orderwcslack_new_order_message$message, $order_id
Order updatewcslack_order_update_message$message, $order_id
Refundwcslack_refund_message$message, $order_id
Subscription renewalwcslack_sub_renew_new_message$message, $order_id
Back orderwcslack_back_order_message$message
Low stockwcslack_low_stock_message$message
Out of stockwcslack_out_stock_message$message
New reviewwcslack_new_review_message$message
New customerwcslack_new_customer_message$message
New postwcslack_new_post_message$message

For example, to add the payment method to every new order message:

add_filter( 'wcslack_new_order_message', function( $message, $order_id ) {
	$order = wc_get_order( $order_id );

	return $order ? $message . ' (' . $order->get_payment_method_title() . ')' : $message;
}, 10, 2 );

Details filters

When Extended is on, the details block below the message is built from a list of fields. Each field is an array with title, an optional value, and short (true puts two fields side by side). The filters run before the line items and totals are added.

EventFilterArguments
New orderwcslack_new_order_attachment$fields, $order_id, $order
Order updatewcslack_order_update_attachment$fields, $order_id, $order
Refundwcslack_refund_attachment$fields, $refund_id, $refund
Subscription renewalwcslack_sub_renew_new_attachment$fields, $order_id, $order
New reviewwcslack_new_review_attachment$fields
New postwcslack_new_post_attachment$fields

Value filters

These change a single value before it goes into the message’s tags.

FilterValue
wcslack_new_review_reviewer_nameThe reviewer’s name
wcslack_new_review_product_nameThe reviewed product’s name
wcslack_new_review_contentThe review text
wcslack_new_review_rating_starThe emoji repeated once per star, :star: by default
wcslack_new_review_urlThe link to the review
wcslack_new_customer_nameThe customer’s display name
wcslack_new_customer_urlThe link to the customer’s profile in your admin
wcslack_new_post_titleThe post title
wcslack_new_post_contentThe post content, with HTML removed
wcslack_new_post_authorThe author’s display name
wcslack_new_post_urlThe post’s address

Other filters

wcslack_message_username

Filters the sender name for every message, including the test notification. It receives the Sender name setting; return an empty string to use the Slack app’s own name.

wcslack_post_publish_types

The post types that send New post, [ 'post', 'page' ] by default. To include products:

add_filter( 'wcslack_post_publish_types', function( $types ) {
	$types[] = 'product';

	return $types;
} );

Stores still on the 1.x connection

Until a store clicks Switch to the new experience, it runs the 1.x code, which also has wcslack_*_prefix filters for each message’s opening text. The settings screen in version 2.0.0 and later doesn’t use those filters, so move any prefix change into the event’s Message field or a message filter when you switch.

Keep learning