get_refunds() as $refund ) { if ( $excluding > 0 && $refund->get_id() === $excluding ) { continue; } $amount = Money::to_minor( (string) $refund->get_amount(), $decimals ); if ( null === $amount ) { return null; } $sum += $amount; } return $sum; } /** * What remains refundable on an order, in minor units, leaving out the * refund being created; null when it cannot be read. * * @param \WC_Order $order The order. * @param int $excluding The refund being created, or 0. * @param int $decimals Minor-unit exponent. */ public static function refundable( \WC_Order $order, int $excluding, int $decimals ): ?int { $total = Money::to_minor( (string) $order->get_total(), $decimals ); $refunded = self::refunded( $order, $excluding, $decimals ); return null === $total || null === $refunded ? null : max( 0, $total - $refunded ); } /** * A money fact's declaration: minor units of the base currency, with * the recorded exponent and the currency's symbol, so the parent's rule * builder shows amounts in store units. * * @param StoreCurrency $currency The store's money. * @param string $label Label. * @return array */ public static function money( StoreCurrency $currency, string $label ): array { $declaration = array( 'type' => 'money', 'label' => $label, 'decimals' => $currency->decimals(), ); $symbol = html_entity_decode( (string) get_woocommerce_currency_symbol( $currency->base() ), ENT_QUOTES, 'UTF-8' ); if ( '' !== $symbol && strlen( $symbol ) <= 8 ) { $declaration['currency'] = $symbol; } return $declaration; } }