WC_Emails::low_stock
Low stock notification email.
Method of the class: WC_Emails{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Emails = new WC_Emails(); $WC_Emails->low_stock( $product );
- $product(WC_Product) (required)
- Product instance.
WC_Emails::low_stock() WC Emails::low stock code WC 10.5.0
public function low_stock( $product ) {
if ( 'no' === get_option( 'woocommerce_notify_low_stock', 'yes' ) ) {
return;
}
/**
* Determine if the current product should trigger a low stock notification
*
* @param int $product_id - The low stock product id
*
* @since 4.7.0
*/
if ( false === apply_filters( 'woocommerce_should_send_low_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( '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 low in stock', 'woocommerce' ) );
$message = sprintf(
/* translators: 1: product name 2: items in stock */
__( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
html_entity_decode( wp_strip_all_tags( $product->get_stock_quantity() ) )
);
$this->add_email_sender_filters();
wp_mail(
/**
* Filter the recipient of the low stock notification email.
*
* @since 3.0.0
* @param string $recipient The recipient email address.
* @param WC_Product $product Product instance.
* @param null $null Unused.
*/
apply_filters( 'woocommerce_email_recipient_low_stock', get_option( 'woocommerce_stock_email_recipient' ), $product, null ),
/**
* Filter the subject of the low stock notification email.
*
* @since 3.0.0
* @param string $subject The email subject.
* @param WC_Product $product Product instance.
* @param null $null Unused.
*/
apply_filters( 'woocommerce_email_subject_low_stock', $subject, $product, null ),
/**
* Filter the content of the low stock notification email.
*
* @since 3.0.0
* @param string $message The email content.
* @param WC_Product $product Product instance.
* @param null $null Unused.
*/
apply_filters( 'woocommerce_email_content_low_stock', $message, $product ),
/**
* Filter the headers of the low stock notification email.
*
* @since 3.0.0
* @param string $headers The email headers.
* @param WC_Product $product Product instance.
* @param null $null Unused.
*/
apply_filters( 'woocommerce_email_headers', '', 'low_stock', $product, null ),
/**
* Filter the attachments of the low stock notification email.
*
* @since 3.0.0
* @param array $attachments The email attachments.
* @param WC_Product $product Product instance.
* @param null $null Unused.
*/
apply_filters( 'woocommerce_email_attachments', array(), 'low_stock', $product, null )
);
$this->remove_email_sender_filters();
}