File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 22
33namespace SkyVerge \WooCommerce \PluginFramework \v5_15_6 \Emails \Traits ;
44
5+ use Automattic \WooCommerce \Internal \Admin \EmailPreview \EmailPreview ;
6+ use WC_Product ;
7+
58/**
69 * Adds improved support for the experimental "Email Improvements" feature, by populating any missing properties
710 * with default/placeholder values.
@@ -14,4 +17,41 @@ trait HasEmailPreviewValuesTrait
1417 * Sets "Preview" values on the email object.
1518 */
1619 abstract public function setPreviewValues () : void ;
20+
21+ /**
22+ * Gets a random, real product from the site.
23+ *
24+ * For use in rendering examples for email templates.
25+ * @return WC_Product|null
26+ */
27+ protected function getRandomProduct () : ?WC_Product
28+ {
29+ $ products = array_values (wc_get_products ([
30+ 'post_type ' => 'product ' ,
31+ 'posts_per_page ' => 1 ,
32+ 'orderby ' => 'rand ' ,
33+ ]));
34+
35+ if (isset ($ products [0 ]) && $ products [0 ] instanceof WC_Product) {
36+ return $ products [0 ];
37+ }
38+
39+ return null ;
40+ }
41+
42+ /**
43+ * Gets a dummy (fake) product.
44+ *
45+ * For use in rendering examples for email templates.
46+ * @return WC_Product
47+ */
48+ protected function getDummyProduct () : WC_Product
49+ {
50+ if (class_exists (EmailPreview::class) && method_exists (EmailPreview::class, 'get_dummy_product_when_not_set ' )) {
51+ return EmailPreview::instance ()->get_dummy_product_when_not_set (null );
52+ } else {
53+ // we should really never end up here!
54+ return new WC_Product ();
55+ }
56+ }
1757}
Original file line number Diff line number Diff line change 11*** SkyVerge WooCommerce Plugin Framework Changelog ***
22
3- 2025.nn.nn - version 5.15.6
3+ 2025.nn.nn - version 5.15.6-dev.1
4+ * New: Added additional helper methods to the trait `HasEmailPreviewValuesTrait`
45
562025.03.05 - version 5.15.5
67* New: Add a trait to assist in compatibility with new WooCommerce email preview feature
You can’t perform that action at this time.
0 commit comments