How to add the product link to low and out of stock emails in WooCommerce?

Photo of author
Written By geekerhub

Lorem ipsum dolor sit amet consectetur pulvinar ligula augue quis venenatis. 

WooCommerce by default gives the product name, SKU, and Stock Quantity in an email when the product will near to low stock threshold. If we need to add a product edit link to the email then this code will help you.

Using this code we will get the product edit link so we can easily edit the product’s stock. It will save time to find products in the backend and update stock.

Add the below code in your functions.php file.

<?php 
	/**
	 * Adds the product link to low and out of stock emails in WooCommerce
	 * @param  string $message Message stating low/out of stock. 
	 * @param  object $product The product's object the email is for. 
	 * @return string The modified email with the link to edit the product. 
	 *
	 * @link https://wordpress.org/support/topic/admin-stock-notification-emails/
	 * @link https://gist.github.com/jessepearson/701386d8ca5e4c84fc7cdf3d5d5391a3
	 */
	function geekerhub_add_prod_url_to_stock_messages( $message, $product ) {
	    return $message ."<br>n". get_edit_post_link( $product->get_id(), '&' );
	}
	add_filter( 'woocommerce_email_content_low_stock', 'geekerhub_add_prod_url_to_stock_messages', 10, 2 );
	add_filter( 'woocommerce_email_content_no_stock', 'geekerhub_add_prod_url_to_stock_messages', 10, 2 );
?>

Leave a Comment