PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Utils / Order.php

Order.php in MultiSafepay plugin for WooCommerce trunk, at src/Utils/Order.php

62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Utils;
4
5 use WC_Order;
6
7 /**
8 * This class defines methods to handle easily different actions related with the WC_Order object
9 */
10 class Order {
11
12 /**
13 * Check if the order is a MultiSafepay order
14 *
15 * @param WC_Order $order
16 * @return bool
17 */
18 public static function is_multisafepay_order( WC_Order $order ): bool {
19 if ( strpos( $order->get_payment_method(), 'multisafepay_' ) !== false ) {
20 return true;
21 }
22
23 return false;
24 }
25
26 /**
27 * Add a note to the order
28 *
29 * @param WC_Order $order
30 * @param string $message
31 * @param bool $on_debug
32 * @return void
33 */
34 public static function add_order_note( WC_Order $order, string $message, bool $on_debug = false ): void {
35 if ( $on_debug && ! get_option( 'multisafepay_debugmode', false ) ) {
36 return;
37 }
38
39 $order->add_order_note( $message );
40 }
41
42 /**
43 * Return WooCommerce Order ID where meta value key is 'multisafepay_transaction_id' and value is $order_id
44 *
45 * @param string $order_id
46 * @return false|mixed|\WC_Order
47 *
48 * @phpcs:disable WordPress.DB.SlowDBQuery
49 */
50 public static function get_order_id_by_multisafepay_transaction_id_key( string $order_id ) {
51 $orders = wc_get_orders(
52 array(
53 'limit' => 1,
54 'meta_key' => 'multisafepay_transaction_id',
55 'meta_value' => $order_id,
56 'return' => 'ids',
57 )
58 );
59 return ! empty( $orders ) ? $orders[0] : false;
60 }
61 }
62