Support » Plugin: Product Specifications for Woocommerce » do_shortcode() Not working in product page template

  • Resolved iconstudiosny


    I’m trying to add the specs table to a product page template by using the WordPress do_shortcode() function but it simply does not work.

    Here’s the code I used in my template: <?php echo do_shortcode('[specs-table]'); ?>

    When I used the same code for different shortcodes such as <?php echo do_shortcode('[related_products limit="2"]'); ?> everything worked just fine and when I tried to use just the shortcode [specs-table] in the product description it also worked fine – I only have thjis issue when using <?php echo do_shortcode('[specs-table]'); ?> in the product template.

    Thanks in advance,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    I’m not the author but I found this problem as well. I managed with this solution:

    $specifications = dw_get_table_result($pid); where $pid is my product id.
    $first_group = array_column($specifications[0]['attributes'], 'value', 'attr_name');
    $second_group = array_column($specifications[1]['attributes'], 'value', 'attr_name');
    $third_group = array_column($specifications[2]['attributes'], 'value', 'attr_name');
    $third_group_unit = array_column($specifications[2]['attributes'], 'attr_desc', 'attr_name');

    etc… my first and second groups are true/false and the third is a input type text where the description is the unit.

    And then I made a foreach loop each like if it’s true/false if it’s text then just simple echo it etc.:

    <?php foreach ($first_group as $group_text => $group_value): ?>
    <?php if ($group_value == 'yes'): ?>
    <li class="product-allergic-li"><?php echo $group_text; ?></li>
    <?php endforeach; ?>

    Limit 2 means you have to use <?php for ?> on the product_id’s array.

    If you have any question feel free to ask.

    Here’s my code based on your snippet:

    foreach(dw_get_table_result($product->get_id()) as $group) {
        echo '<h5>' . $group[group_name] . '</h5>';
        foreach($group[attributes] as $attr) {
            echo '<p><strong>' . $attr[attr_name] . '</strong>';
            echo ': ' . $attr[value] . '</p>';

    Here is what it returns:

    Group 1
    Attribute 1: Value
    Attribute 2: Value
    Attribute 3: Value

    Group 2
    Attribute 1: Value
    Attribute 2: Value
    Attribute 3: Value

    Thank you @cziberez for your help on the initial code,

    If you’re using the shortcode outside a loop, adding the post_id attribute will help :
    <?php echo do_shortcode('[specs-table post_id=123]'); ?>

    where 123 is your product id.

    Hey, I didn’t know the shortcode supports a post_id attribute, why is it not mentioned in the plugin’s description or FAQ section????!

    Thank you @pelentak

    Plugin Author Amin


    @iconstudiosny I’m sorry for the incomplete FAQ, but yes, the shortcode does support a post_id value.

    No problem @dornaweb

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘do_shortcode() Not working in product page template’ is closed to new replies.