| @@ -24,8 +24,10 @@ | ||
| 24 | 24 | add_action( 'get_footer', [ $this, 'get_footer' ], 0 ); |
| 25 | 25 | add_action( 'elementor/document/wrapper_attributes', [ $this, 'wrapper_attributes' ], 10, 2 ); |
| 26 | 26 | add_action( 'template_redirect', array( $this, 'set_global_product' ) ); |
| 27 | 27 | |
| 28 | + add_action( 'templately_builder_header_after', [ $this, 'print_style_tags' ], 0 ); | |
| 29 | + add_action( 'templately_builder_footer_before', [ $this, 'print_style_tags' ], 0 ); | |
| 28 | 30 | /** |
| 29 | 31 | * Only for Development Mode. |
| 30 | 32 | */ |
| 31 | 33 | if ( defined( 'TEMPLATELY_DEV_VIEWS' ) && TEMPLATELY_DEV_VIEWS ) { |
| @@ -134,9 +136,30 @@ | ||
| 134 | 136 | if ( class_exists('\WC_Product') && ! $product instanceof \WC_Product ) { |
| 135 | 137 | $product_id = get_the_ID(); |
| 136 | 138 | if ( $product_id ) { |
| 137 | 139 | wc_setup_product_data( $product_id ); |
| 140 | + } | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Print remaining enqueued styles with error handling. | |
| 146 | + */ | |
| 147 | + public function print_style_tags() { | |
| 148 | + try { | |
| 149 | + $wp_styles = wp_styles(); | |
| 150 | + | |
| 151 | + if ( is_object( $wp_styles ) && is_array( $wp_styles->queue ?? null ) ) { | |
| 152 | + foreach ( $wp_styles->queue as $style ) { | |
| 153 | + if ( is_string( $style ) && ! $wp_styles->query( $style, 'done' ) ) { | |
| 154 | + $wp_styles->do_item( $style ); | |
| 155 | + } | |
| 156 | + } | |
| 157 | + } | |
| 158 | + } catch ( \Throwable $e ) { | |
| 159 | + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
| 160 | + error_log( 'Templately: Error printing styles - ' . $e->getMessage() ); | |
| 138 | 161 | } |
| 139 | 162 | } |
| 140 | 163 | } |
| 141 | 164 | |
| 142 | 165 | } |