PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Internal / StockNotifications / Factory.php
Factory.php
64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Notification Factory
4 */
5
6 declare( strict_types = 1 );
7
8 namespace Automattic\WooCommerce\Internal\StockNotifications;
9
10 use Automattic\WooCommerce\Internal\StockNotifications\Notification;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Notification factory class
16 */
17 class Factory {
18
19 /**
20 * Get the notification object.
21 *
22 * @param int $notification_id Notification ID to get.
23 * @return Notification|bool
24 */
25 public static function get_notification( int $notification_id ) {
26
27 if ( ! $notification_id ) {
28 return false;
29 }
30
31 try {
32 $notification = new Notification( $notification_id );
33 return $notification;
34 } catch ( \Exception $e ) {
35 \wc_caught_exception( $e, __FUNCTION__, array( $notification_id ) );
36 return false;
37 }
38 }
39
40 /**
41 * Create a dummy notification for preview/testing purposes.
42 *
43 * @return Notification
44 */
45 public static function create_dummy_notification(): Notification {
46 $notification = new Notification();
47
48 // Create a dummy product.
49 $product = new \WC_Product();
50 $product->set_name( __( 'Dummy Product', 'woocommerce' ) );
51 $product->set_price( 25 );
52 $product->set_image_id( get_option( 'woocommerce_placeholder_image', 0 ) );
53
54 // Set required notification data.
55 $notification->set_product_id( $product->get_id() );
56 $notification->set_user_email( 'preview@example.com' );
57
58 // Store the dummy product in the notification object for preview.
59 $notification->product = $product;
60
61 return $notification;
62 }
63 }
64