Class wc emails backorder method extract function removed (#17724)

* Replaced extract() function usage.

Usage of `extract()` is kinda discouraged. Though here the array `$args` is verified, I think avoiding this `extract()` function will make it better. Besides, without `extract()` the code is more readable and easily understandable.

* Object checking should be done.

Checking `$args['product']` is an object or not should be done before `get_formatted_name()` method is being called.
This commit is contained in:
The Dramatist 2017-11-17 17:38:26 +06:00 committed by Mike Jolley
parent 885d0aa415
commit 85ce4e0078
1 changed files with 9 additions and 5 deletions

View File

@ -558,15 +558,19 @@ class WC_Emails {
'order_id' => '',
) );
extract( $args );
if ( ! $product || ! $quantity || ! ( $order = wc_get_order( $order_id ) ) ) {
$order = wc_get_order( $args['order_id'] );
if (
! $args['product'] ||
! is_object( $args['product'] ) ||
! $args['quantity'] ||
! $order
) {
return;
}
$subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) );
$message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $quantity, html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
$message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $args['quantity'], html_entity_decode( strip_tags( $args['product']->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
wp_mail(
apply_filters( 'woocommerce_email_recipient_backorder', get_option( 'woocommerce_stock_email_recipient' ), $args ),
apply_filters( 'woocommerce_email_subject_backorder', $subject, $args ),