WC_Emails::no_stockpublicWC 1.0

No stock notification email.

Method of the class: WC_Emails{}

Returns

null. Nothing (null).

Usage

$WC_Emails = new WC_Emails();
$WC_Emails->no_stock( $product );
$product(WC_Product) (required)
Product instance.

WC_Emails::no_stock() code WC 9.9.3

public function no_stock( $product ) {
	if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) {
		return;
	}

	/**
	 * Determine if the current product should trigger a no stock notification
	 *
	 * @param int $product_id - The out of stock product id
	 *
	 * @since 4.6.0
	 */
	if ( false === apply_filters( 'woocommerce_should_send_no_stock_notification', true, $product->get_id() ) ) {
		return;
	}

	// If this is a variation but stock is managed at the parent level, use the parent product for the notification.
	if ( $product->is_type( ProductType::VARIATION ) && 'parent' === $product->get_manage_stock() ) {
		$parent_product = wc_get_product( $product->get_parent_id() );
		if ( $parent_product ) {
			$product = $parent_product;
		}
	}

	$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product out of stock', 'woocommerce' ) );
	/* translators: %s: product name */
	$message = sprintf( __( '%s is out of stock.', 'woocommerce' ), html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) );

	wp_mail(
		apply_filters( 'woocommerce_email_recipient_no_stock', get_option( 'woocommerce_stock_email_recipient' ), $product, null ),
		apply_filters( 'woocommerce_email_subject_no_stock', $subject, $product, null ),
		apply_filters( 'woocommerce_email_content_no_stock', $message, $product ),
		apply_filters( 'woocommerce_email_headers', '', 'no_stock', $product, null ),
		apply_filters( 'woocommerce_email_attachments', array(), 'no_stock', $product, null )
	);
}