JustTables Shortcode

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

Before starting, here is an overview of the JustTables Plugin and the shortcodes it provides:

Plugin Icon
JustTables – WooCommerce Product Table

JustTables – WooCommerce Product Table is a powerful plugin that transforms your WooCommerce store into a responsive, user-friendly product table, enhancing your customers' shopping experience.

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

JustTables [JT_Product_Table] Shortcode

The Just-Tables shortcode, ‘JT_Product_Table’, is used to render a product table on a webpage. It requires an ‘id’ attribute which is the post ID of the product table. If the ‘id’ is not provided, the shortcode is invalid. Also, if the product table does not exist, is in the trash, or is not published and the user doesn’t have read permissions, it returns an error. If the post is password-protected, it displays the password form. Otherwise, it fetches the product table options and includes the necessary files to display the table. If the table HTML is not set or is empty, it returns an empty string.

Shortcode: [JT_Product_Table]

Parameters

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

  • id – specifies the unique ID of the product table to display

Examples and Usage

Basic example – Display a product table by referencing its ID.

[JT_Product_Table id=1 /]

Advanced examples

Display a product table by referencing its ID. If the table is not found or is in the trash, an error message will be displayed. If the table is password protected, a password form will be displayed. If the table is not published and the current user does not have read permissions, nothing will be displayed.

[JT_Product_Table id=2 /]

Display a product table by referencing its ID. If the table is not found or is in the trash, an error message will be displayed. If the table is password protected, a password form will be displayed. If the table is not published and the current user does not have read permissions, nothing will be displayed. If the table has no options set, an empty table will be displayed.

[JT_Product_Table id=3 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'JT_Product_Table', array( $this, 'render_shortcode' ) );

Shortcode PHP function:

function render_shortcode( $atts ) {
    	$atts = shortcode_atts(
			array(
				'id' => '',
			),
			$atts,
			'JT_Product_Table'
		);

		$table_id = absint( $atts['id'] );

		$invalid_shortcode_message = '<p class="jtpt-shortcode-error">' . esc_html__( 'Please provide a valid shortcode!', 'just-tables' ) . '</p>';

		if ( empty( $table_id ) ) {
			return $invalid_shortcode_message;
		}

		$product_table = get_post( $table_id );

		if ( empty( $product_table ) || ( 'jt-product-table' !== $product_table->post_type ) ) {
			return $invalid_shortcode_message;
		}

		$product_table_status = $product_table->post_status;

		if ( 'trash' === $product_table_status ) {
			return $invalid_shortcode_message;
		}

		if ( ( 'publish' !== $product_table_status ) && ! current_user_can( 'read', $table_id ) ) {
			return;
		}

		if ( post_password_required( $table_id ) ) {
			return get_the_password_form();
		} else {
			$product_table_options = get_post_meta( $table_id, '_jt_product_table_options', true );

			if ( ! isset( $product_table_options ) || ! is_array( $product_table_options ) || empty( $product_table_options ) ) {
				$product_table_options = array();
			}

			include __DIR__ . '/views/columns-options.php';
			include __DIR__ . '/views/config-options.php';
			include __DIR__ . '/views/table.php';

			if ( ! isset( $table_html ) || ! is_string( $table_html ) || empty( $table_html ) ) {
				$table_html = '';
			}

			return $table_html;
		}
    }

Code file location:

just-tables/just-tables/includes/Frontend/Shortcode.php

Conclusion

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