Astra_Enqueue_Scripts::has_elementor_product_widget()

Check if page has Elementor product widget.


Description


Return

(bool)


Source

File: inc/core/class-astra-enqueue-scripts.php

		public static function has_elementor_product_widget() {
			// Check if Elementor is active.
			if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
				return false;
			}

			// Check if we're on a page that might have Elementor product widgets.
			if ( ! is_singular() ) {
				return false;
			}

			// Check for Elementor data with product-related widgets.
			$post_id = get_the_ID();
			if ( ! $post_id ) {
				return false;
			}

			// Check if post is built with Elementor.
			if ( ! get_post_meta( $post_id, '_elementor_version', true ) ) {
				return false;
			}

			// Get Elementor data.
			$elementor_data = get_post_meta( $post_id, '_elementor_data', true );
			if ( ! $elementor_data ) {
				return false;
			}

			// Check for WooCommerce-related Elementor widgets.
			$woo_widgets = array(
				'woocommerce-menu-cart',
				'woocommerce-product-images',
				'woocommerce-product-meta',
				'woocommerce-product-price',
				'woocommerce-product-rating',
				'woocommerce-product-short-description',
				'woocommerce-product-stock',
				'woocommerce-product-tabs',
				'woocommerce-product-title',
				'woocommerce-product-additional-information',
				'woocommerce-product-data-tabs',
				'woocommerce-products',
				'woocommerce-categories',
				'wc-archive-products',
				'wc-single-product',
			);

			// Check if any WooCommerce widgets exist in Elementor data.
			foreach ( $woo_widgets as $widget ) {
				if ( strpos( $elementor_data, $widget ) !== false ) {
					return true;
				}
			}

			return false;
		}

Changelog

Changelog
Version Description
4.11.18 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.