PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / BlockLibrary / ProductQuickViewService.php
ProductQuickViewService.php
63 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\BlockLibrary;
4
5 /**
6 * The quick view service.
7 */
8 class ProductQuickViewService {
9 /**
10 * Flag to track if template has been rendered.
11 *
12 * @var bool
13 */
14 private static $rendered = false;
15
16 /**
17 * Include quick view template.
18 * This needs to run before <head> so that blocks can add scripts and styles in wp_head().
19 *
20 * @return void
21 */
22 public function render() {
23 // Only render the template once per page load.
24 if ( self::$rendered ) {
25 return;
26 }
27
28 // do this before the footer so we can print late styles.
29 $quick_view_template = $this->getTemplate();
30
31 // add cart template to footer.
32 add_action(
33 'wp_footer',
34 function () use ( $quick_view_template ) {
35 echo $quick_view_template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
36 }
37 );
38
39 // Mark template as rendered.
40 self::$rendered = true;
41 }
42
43 /**
44 * Get the cart template.
45 *
46 * @return string
47 */
48 public function getTemplate() {
49 // get cart block.
50 $template = get_block_template( 'surecart/surecart//product-quick-view', 'wp_template_part' );
51 if ( ! $template || empty( $template->content ) ) {
52 return;
53 }
54
55 ob_start();
56
57 // Render the product quick view.
58 echo do_blocks( $template->content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
59
60 return trim( preg_replace( '/\s+/', ' ', ob_get_clean() ) );
61 }
62 }
63