Automattic\WooCommerce\Internal\PushNotifications\Notifications
NewOrderNotification::get_suppression_reason
{@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.
Метод класса: NewOrderNotification{}
Хуков нет.
Возвращает
string|null. One of the SuppressionReason constants, or null to send.
Использование
$NewOrderNotification = new NewOrderNotification(); $NewOrderNotification->get_suppression_reason( $pref_value ): ?string;
- $pref_value(разное) (обязательный)
- The user's stored preference value, or null.
Список изменений
| С версии 11.3.0 | Введена. |
Код NewOrderNotification::get_suppression_reason() NewOrderNotification::get suppression reason WC 11.3.0
public function get_suppression_reason( $pref_value ): ?string {
$reason = parent::get_suppression_reason( $pref_value );
if ( null !== $reason ) {
return $reason;
}
if ( ! is_array( $pref_value ) || ! isset( $pref_value['min_amount'] ) ) {
return null;
}
$min_amount = (float) $pref_value['min_amount'];
if ( $min_amount <= 0 ) {
return null;
}
$order = WC()->call_function( 'wc_get_order', $this->get_resource_id() );
if ( ! $order instanceof WC_Order ) {
return SuppressionReason::ORDER_MISSING;
}
return (float) $order->get_total() >= $min_amount ? null : SuppressionReason::BELOW_MIN_AMOUNT;
}