| @@ -22,8 +22,9 @@ | ||
| 22 | 22 | |
| 23 | 23 | add_action( 'get_header', [ $this, 'get_header' ], 0 ); |
| 24 | 24 | add_action( 'get_footer', [ $this, 'get_footer' ], 0 ); |
| 25 | 25 | add_action( 'elementor/document/wrapper_attributes', [ $this, 'wrapper_attributes' ], 10, 2 ); |
| 26 | + add_action( 'template_redirect', array( $this, 'set_global_product' ) ); | |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * Only for Development Mode. |
| 29 | 30 | */ |
| @@ -41,9 +42,9 @@ | ||
| 41 | 42 | echo '<small>Footer</small>'; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | public function get_header() { |
| 45 | - if(!$this->is_header_footer()){ | |
| 46 | + if(!self::is_header_footer('header')){ | |
| 46 | 47 | return; |
| 47 | 48 | } |
| 48 | 49 | $this->views->get_header(); |
| 49 | 50 | |
| @@ -57,9 +58,9 @@ | ||
| 57 | 58 | ob_get_clean(); |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | public function get_footer( $name ) { |
| 61 | - if(!$this->is_header_footer()){ | |
| 62 | + if(!self::is_header_footer('footer')){ | |
| 62 | 63 | return; |
| 63 | 64 | } |
| 64 | 65 | $this->views->get_footer(); |
| 65 | 66 | |
| @@ -77,9 +78,9 @@ | ||
| 77 | 78 | locate_template( $templates, true ); |
| 78 | 79 | ob_get_clean(); |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | - public function is_header_footer(){ | |
| 82 | + public static function is_header_footer($type = null){ | |
| 82 | 83 | if(class_exists( 'Elementor\Plugin' )){ |
| 83 | 84 | $pid = get_the_ID(); |
| 84 | 85 | $post_type = get_post_type($pid); |
| 85 | 86 | $document = Plugin::$instance->documents->get( $pid ); |
| @@ -96,8 +97,15 @@ | ||
| 96 | 97 | |
| 97 | 98 | $header = templately()->theme_builder::$conditions_manager->get_templates_by_location( 'header' ); |
| 98 | 99 | $footer = templately()->theme_builder::$conditions_manager->get_templates_by_location( 'footer' ); |
| 99 | 100 | |
| 101 | + if($type === 'header'){ | |
| 102 | + return $header; | |
| 103 | + } | |
| 104 | + else if($type === 'footer'){ | |
| 105 | + return $footer; | |
| 106 | + } | |
| 107 | + | |
| 100 | 108 | if(!empty($header) || !empty($footer)){ |
| 101 | 109 | return true; |
| 102 | 110 | } |
| 103 | 111 | return false; |
| @@ -106,15 +114,29 @@ | ||
| 106 | 114 | public function wrapper_attributes( $attributes, $document ) { |
| 107 | 115 | $post_type = get_post_type($document->get_main_id()); |
| 108 | 116 | |
| 109 | 117 | if( $post_type === 'templately_library' ){ |
| 110 | - $template = templately()->theme_builder->get_template( $document->get_main_id() ); | |
| 111 | - $attributes['data-elementor-type'] = 'templately-' . $template->get_type(); | |
| 112 | - $attributes['data-elementor-id'] = $template->get_main_id(); | |
| 113 | - $attributes['data-elementor-post-type'] = 'templately_library'; | |
| 114 | - $attributes['data-elementor-title'] = $template->get_title(); | |
| 118 | + $template = templately()->theme_builder->get_template( $document->get_main_id() ); | |
| 119 | + if($template){ | |
| 120 | + $attributes['data-elementor-type'] = 'templately-' . $template->get_type(); | |
| 121 | + $attributes['data-elementor-id'] = $template->get_main_id(); | |
| 122 | + $attributes['data-elementor-post-type'] = 'templately_library'; | |
| 123 | + $attributes['data-elementor-title'] = $template->get_title(); | |
| 124 | + $attributes['class'] .= ' ' . implode( ' ', get_post_class() ); | |
| 125 | + } | |
| 115 | 126 | } |
| 116 | 127 | |
| 117 | 128 | return $attributes; |
| 129 | + } | |
| 130 | + | |
| 131 | + public function set_global_product(){ | |
| 132 | + global $product; | |
| 133 | + | |
| 134 | + if ( class_exists('\WC_Product') && ! $product instanceof \WC_Product ) { | |
| 135 | + $product_id = get_the_ID(); | |
| 136 | + if ( $product_id ) { | |
| 137 | + wc_setup_product_data( $product_id ); | |
| 138 | + } | |
| 139 | + } | |
| 118 | 140 | } |
| 119 | 141 | |
| 120 | 142 | } |