Automattic\WooCommerce\Internal\PushNotifications\Notifications
NewOrderNotification::should_send_to_user
{@inheritDoc}
Extends the base enabled-toggle check with a minimum-amount threshold. When min_amount is set in the user's preferences, the order total must meet or exceed it for the notification to be sent.
The threshold is interpreted in the order's currency; no currency conversion is performed. This mirrors how WC_Coupon::minimum_amount behaves, so multi-currency merchants should set thresholds with that in mind.
Method of the class: NewOrderNotification{}
No Hooks.
Returns
true|false.
Usage
$NewOrderNotification = new NewOrderNotification(); $NewOrderNotification->should_send_to_user( $pref_value ): bool;
- $pref_value(mixed) (required)
- The user's stored preference value, or null.
Changelog
| Since 10.9.0 | Introduced. |
NewOrderNotification::should_send_to_user() NewOrderNotification::should send to user code WC 10.9.1
public function should_send_to_user( $pref_value ): bool {
if ( ! parent::should_send_to_user( $pref_value ) ) {
return false;
}
if ( ! is_array( $pref_value ) || ! isset( $pref_value['min_amount'] ) ) {
return true;
}
$min_amount = (float) $pref_value['min_amount'];
if ( $min_amount <= 0 ) {
return true;
}
$order = WC()->call_function( 'wc_get_order', $this->get_resource_id() );
if ( ! $order instanceof WC_Order ) {
return false;
}
return (float) $order->get_total() >= $min_amount;
}