| @@ -3,8 +3,10 @@ | ||
| 3 | 3 | namespace Sellkit\Admin\Settings\Integration; |
| 4 | 4 | |
| 5 | 5 | defined( 'ABSPATH' ) || die(); |
| 6 | 6 | |
| 7 | +use Sellkit\Global_Checkout\Checkout as Global_Checkout; | |
| 8 | + | |
| 7 | 9 | /** |
| 8 | 10 | * Class Google Analytics and Facebook Pixel integration. |
| 9 | 11 | * |
| 10 | 12 | * @package Sellkit\Admin\Settings\Integration\Settings_Integration |
| @@ -73,19 +75,29 @@ | ||
| 73 | 75 | */ |
| 74 | 76 | public function google_facebook_analytics() { |
| 75 | 77 | global $post; |
| 76 | 78 | |
| 79 | + $step_meta = $this->get_step_meta( $post ); | |
| 80 | + | |
| 77 | 81 | if ( |
| 78 | 82 | empty( $post ) || |
| 79 | - empty( get_post_meta( $post->ID, 'step_data' ) ) || | |
| 83 | + empty( $step_meta ) || | |
| 80 | 84 | $this->is_elementor_preview() |
| 81 | 85 | ) { |
| 82 | 86 | return; |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | - self::$post = get_post_meta( $post->ID, 'step_data' ); | |
| 89 | + self::$post = $step_meta; | |
| 86 | 90 | self::$order_key = sellkit_htmlspecialchars( INPUT_GET, 'order-key' ); |
| 87 | 91 | |
| 92 | + if ( empty( self::$order_key ) ) { | |
| 93 | + self::$order_key = sellkit_htmlspecialchars( INPUT_GET, 'key' ); | |
| 94 | + } | |
| 95 | + | |
| 96 | + if ( ! sellkit()->has_valid_dependencies() ) { | |
| 97 | + self::$order_key = null; | |
| 98 | + } | |
| 99 | + | |
| 88 | 100 | sellkit()->load_files( |
| 89 | 101 | [ |
| 90 | 102 | 'admin/settings/integration/google-integration', |
| 91 | 103 | 'admin/settings/integration/facebook-integration', |
| @@ -92,8 +104,90 @@ | ||
| 92 | 104 | ] |
| 93 | 105 | ); |
| 94 | 106 | |
| 95 | 107 | wp_localize_script( 'funnel-settings-variables', 'sellkitSettings', self::$localized_data ); |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Get step meta. | |
| 112 | + * | |
| 113 | + * @param object $post post object. | |
| 114 | + * @since 2.3.0 | |
| 115 | + * @return array|void | |
| 116 | + */ | |
| 117 | + private function get_step_meta( $post ) { | |
| 118 | + if ( empty( $post ) ) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + | |
| 122 | + $step_meta = get_post_meta( $post->ID, 'step_data' ); | |
| 123 | + | |
| 124 | + if ( ! empty( $step_meta ) ) { | |
| 125 | + return $step_meta; | |
| 126 | + } | |
| 127 | + | |
| 128 | + $global_checkout_id = get_option( Global_Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 ); | |
| 129 | + | |
| 130 | + if ( empty( $global_checkout_id ) ) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + | |
| 134 | + if ( 'publish' !== get_post_status( $global_checkout_id ) ) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + | |
| 138 | + $global_chekout_nodes = get_post_meta( $global_checkout_id, 'nodes' ); | |
| 139 | + | |
| 140 | + if ( empty( $global_chekout_nodes ) ) { | |
| 141 | + return; | |
| 142 | + } | |
| 143 | + | |
| 144 | + $global_chekout_nodes = $global_chekout_nodes[0]; | |
| 145 | + $global_chekout_nodes = $this->check_global_checkout_steps( $global_chekout_nodes, $post->ID ); | |
| 146 | + | |
| 147 | + if ( empty( $global_chekout_nodes ) ) { | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + | |
| 151 | + return $global_chekout_nodes; | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Check global checkout steps. | |
| 156 | + * | |
| 157 | + * @param array $global_chekout_nodes global checkout nodes. | |
| 158 | + * @param int $post_id post id. | |
| 159 | + * @since 2.3.0 | |
| 160 | + * @return array | |
| 161 | + */ | |
| 162 | + private function check_global_checkout_steps( $global_chekout_nodes, $post_id ) { | |
| 163 | + $default_checkout_page = intval( get_option( 'woocommerce_checkout_page_id', 0 ) ); | |
| 164 | + $default_thankyou_page = is_checkout() && ! empty( is_wc_endpoint_url( 'order-received' ) ); | |
| 165 | + $is_checkout_page = is_checkout() && empty( is_wc_endpoint_url( 'order-received' ) ); | |
| 166 | + | |
| 167 | + $new_nodes = []; | |
| 168 | + | |
| 169 | + if ( $default_checkout_page !== $post_id && $default_thankyou_page ) { | |
| 170 | + return []; | |
| 171 | + } | |
| 172 | + | |
| 173 | + foreach ( $global_chekout_nodes as $node ) { | |
| 174 | + if ( 'checkout' === $node['type']['key'] && ! empty( $default_checkout_page ) && $is_checkout_page ) { | |
| 175 | + $new_nodes[ $default_checkout_page ] = $node; | |
| 176 | + continue; | |
| 177 | + } | |
| 178 | + | |
| 179 | + if ( 'thankyou' === $node['type']['key'] && ! empty( $default_thankyou_page ) ) { | |
| 180 | + $new_nodes[ $post_id ] = $node; | |
| 181 | + continue; | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + if ( ! isset( $new_nodes[ $post_id ] ) ) { | |
| 186 | + return []; | |
| 187 | + } | |
| 188 | + | |
| 189 | + return $new_nodes; | |
| 96 | 190 | } |
| 97 | 191 | |
| 98 | 192 | /** |
| 99 | 193 | * Check is elementor preview. |