Dynamic Product Gallery for WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Dynamic Product Gallery for WooCommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Dynamic Product Gallery for WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Dynamic Product Gallery for WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Dynamic Product Gallery for WooCommerce

"Dynamic Product Gallery for WooCommerce is a robust plugin that enhances your online store's product display. It dynamically changes the gallery layout for a more interactive shopping experience."

★★★✩✩ (38) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [wc_product_dgallery]

Dynamic Product Gallery for WooCommerce [wc_product_dgallery] Shortcode

The WooCommerce Dynamic Gallery shortcode allows you to dynamically display a product gallery. It’s initiated with the ‘wc_product_dgallery’ shortcode. The shortcode fetches the product ID and checks if the dynamic gallery feature is activated. If active, it initializes the dynamic gallery for the specified product and returns the gallery HTML.

Shortcode: [wc_product_dgallery]

Parameters

Here is a list of all possible wc_product_dgallery shortcode parameters and attributes:

  • product_id – Specifies the unique identifier of the product

Examples and Usage

Basic Example – Utilizes the ‘wc_product_dgallery’ shortcode to display the dynamic gallery of the current product.

[wc_product_dgallery]

Advanced Examples

Displaying the dynamic gallery for a specific product by referencing the product id. Here, the product id is 25.

[wc_product_dgallery product_id=25]

Also, you can use the shortcode within a PHP function. This can be useful when you want to incorporate the dynamic gallery within a template file. In this example, we are using the do_shortcode function to execute the ‘wc_product_dgallery’ shortcode and display the dynamic gallery of the product with id 25.

<?php echo do_shortcode('[wc_product_dgallery product_id=25]'); ?>

PHP Function Code

In case you have difficulties debugging what causing issues with [wc_product_dgallery] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wc_product_dgallery', array( '\A3Rev\WCDynamicGallery\Shortcodes', 'parse_shortcode_product_dynamic_gallery' ) );

Shortcode PHP function:

                    function parse_shortcode_product_dynamic_gallery( $attributes ) {
		// Don't show content for shortcode on Dashboard, still support for admin ajax
		if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) return;

		if ( ! is_array( $attributes ) ) {
			$attributes = array();
		}

		$attr = array_merge(array(
			'product_id' => '', // leave empty for current product
        ), $attributes );

        $product_id = esc_attr( $attr['product_id'] );	// XSS ok

        $product_id = Functions::get_current_product_id( $product_id );

        if ( empty( $product_id ) ) {
        	return '';
        }

        $gallery_html = '';

		$global_wc_dgallery_activate = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'activate' );

		$actived_d_gallery = 0;
		if ( 'no' != $global_wc_dgallery_activate ) {
			$actived_d_gallery = 1;
		}

		if ( 1 == $actived_d_gallery ) {
			Main::init_dynamic_gallery( $product_id, is_product() );

			ob_start();
			Main::wc_dynamic_gallery_display( $product_id, true );

			$gallery_html = ob_get_clean();
		}

        return $gallery_html;
	}
                    

Code file location:

woocommerce-dynamic-gallery/woocommerce-dynamic-gallery/admin/wc_gallery_woocommerce_admin.php

Conclusion

Now that you’ve learned how to embed the Dynamic Product Gallery for WooCommerce Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *