Product Slider for WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Product Slider 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 Product Slider for WooCommerce Plugin shortcode not to show or not to work correctly.

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

Plugin Icon
Product Slider for WooCommerce

"Product Slider for WooCommerce is a powerful plugin that allows you to showcase your WooCommerce products in a stylish sliding manner. This plugin enhances your store's visual appeal and user experience."

★★★★☆ (238) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [woo_product_slider]

Product Slider for WooCommerce [woo_product_slider] Shortcode

The Woo Product Slider shortcode provides a dynamic slider for WooCommerce products. It checks if WooCommerce is active, fetches the product data, and displays the slider. It enqueues necessary stylesheets and loads dynamic style based on the product data. If WooCommerce is inactive, it returns a prompt to activate the plugin.

Shortcode: [woo_product_slider]

Parameters

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

  • id – The unique identifier of the WooCommerce product slider.

Examples and Usage

Basic example – Display a WooCommerce product slider using the shortcode by referencing the id of the slider. The slider will load based on the specified id.

[woo_product_slider id=3 /]

Advanced examples

Display a WooCommerce product slider using the shortcode by referencing the id of the slider and specifying additional parameters. In this example, the slider will load based on the specified id and the additional parameters will determine the slider’s functionality.

[woo_product_slider id=3 autoplay=true loop=true /]

Another advanced usage includes the ability to reference multiple ids, allowing for the display of multiple sliders. Each slider will load based on its respective id.

[woo_product_slider id=3,4,5 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'woo_product_slider', array( $this, 'wps_shortcode' ) );

Shortcode PHP function:

function wps_shortcode( $attributes ) {
		if ( ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) && ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
			return '<div class="error"><p>You must install and activate <a target="_blank" href="https://wordpress.org/plugins/woocommerce/"><strong>WooCommerce</strong></a> plugin to make the <strong>Product Slider for WooCommerce</strong> work.</p></div>';
		}
		shortcode_atts(
			array(
				'id' => '',
			),
			$attributes,
			'woo_product_slider'
		);
		if ( empty( $attributes['id'] ) || 'sp_wps_shortcodes' !== get_post_type( $attributes['id'] ) || 'trash' === get_post_status( $attributes['id'] ) ) {
			return;
		}
		$post_id            = esc_attr( intval( $attributes['id'] ) );
		$shortcode_data     = get_post_meta( $post_id, 'sp_wps_shortcode_options', true );
		$main_section_title = get_the_title( $post_id );
		ob_start();
		// Stylesheet loading problem solving here. Shortcode id to push page id option for getting how many shortcode in the page.
		$get_page_data      = self::get_page_data();
		$found_generator_id = $get_page_data['generator_id'];
		// This shortcode id not in page id option. Enqueue stylesheets in shortcode.
		if ( ! is_array( $found_generator_id ) || ! $found_generator_id || ! in_array( $post_id, $found_generator_id ) ) {
			wp_enqueue_style( 'sp-wps-swiper' );
			wp_enqueue_style( 'sp-wps-font-awesome' );
			wp_enqueue_style( 'sp-wps-style' );
			// Load dynamic style.
			$dynamic_style = self::load_dynamic_style( $post_id, $shortcode_data );
			echo '<style id="sp_product_slider_dynamic_css' . esc_attr( $post_id ) . '">' . wp_strip_all_tags( $dynamic_style['dynamic_css'] ) . '</style>';  // phpcs:ignore
		}

		// Update options if the existing shortcode id option not found.
		self::wps_db_options_update( $post_id, $get_page_data );
		Helper::spwps_html_show( $post_id, $shortcode_data, $main_section_title );
		return ob_get_clean();
	}

Code file location:

woo-product-slider/woo-product-slider/src/Frontend/Frontend.php

Conclusion

Now that you’ve learned how to embed the Product Slider 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 *