Tips and Tricks HQ Support

Support site for Tips and Tricks HQ premium products

  • Home
  • Contact Us
  • Documentation
  • Forum Home
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration

Display 'add to cart' button in the excerpt

by

Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › Display 'add to cart' button in the excerpt

Tagged: custom fields, excerpt, shortcodes

  • This topic has 13 replies, 5 voices, and was last updated 10 years, 11 months ago by dgitaly.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • March 17, 2011 at 5:07 pm #2974
    dangermoose
    Spectator

    Hi there,

    I’ve got an events page where I list a number of events (as posts using a normal blog template).

    I can easily add the ‘add to cart’ button to the ‘single’ post page but I wonder is there a way to display the button on the list page also which currently displays only the excerpt or a certain number of characters..

    I’d ideally like to show a few lines of text and the ‘add to cart’ button.

    Many thanks..

    March 17, 2011 at 7:41 pm #30316
    dangermoose
    Spectator

    Or maybe I could add the add to cart shortcode to a custom field?

    March 18, 2011 at 12:13 am #30317
    amin007
    Participant

    By default shortcode filtering in the excerpt is off. You can add this option by doing the following:

    1. Open the “wp_eStore1.php” file

    2. Add the following line of code at the bottom of this file (just before the “?>” line is fine):

    add_filter('the_excerpt', 'do_shortcode');

    March 18, 2011 at 8:58 am #30318
    dangermoose
    Spectator

    Thanks for that, I’ve added the code but it doesnt seem to have any effect.

    Do you think I could set the shortcode as a custom field? That way, I guess the client would have to add the shortcode in the post (to display the button on the single post page) as well as the custom field (to display in the events list) but that shouldn’t be an issue.

    March 19, 2011 at 12:35 am #30319
    amin007
    Participant

    That would mean that this theme is not using WordPress’s excerpt function to display the excerpt (some themes like to make their own function for this.. I don’t know why).

    I am not sure if you can just place a plain WordPress shortcode in a custom field but you can do the following:

    https://support.tipsandtricks-hq.com/forums/topic/call-product-through-a-custom-field

    https://support.tipsandtricks-hq.com/forums/topic/custom-fields-within-php-shortcodes

    March 22, 2011 at 3:09 pm #30320
    dangermoose
    Spectator

    Many thanks, I added the following and it works beautifully. Much appreciated!

    <?php
    $values = get_post_custom_values('prodid');
    echo get_button_code_for_product($values[0]);
    ?>

    May 17, 2011 at 2:50 am #30321
    toolance
    Member

    Hi Dangermoose,

    This looks like it might be my solution but where would I paste this code? In wp_estore1.php or in archive.php? And where in the script should it go?

    Thanks in advance

    Hardgristle

    May 17, 2011 at 5:07 am #30322
    amin007
    Participant

    As mentioned in a previous post… you do the following to add shortcode filtering in excerpt:

    1. Open the “wp_eStore1.php” file

    2. Add the following line of code at the bottom of this file (just before the “?>” line is fine):

    add_filter('the_excerpt', 'do_shortcode');

    June 30, 2014 at 3:37 pm #30323
    dgitaly
    Member

    Hello,

    I was trying to add wp estore shortcodes in the post excerpt (wp 3.9.1) but it doesn’t work.

    I’ve also followed your instructions and opened “wp_eStore1.php” and added the add_filter code but also this didn’t work.

    Has something changed since your last answer?

    Thank you

    June 30, 2014 at 5:29 pm #30324
    dgitaly
    Member

    Hello again,

    so far I added the following code to my functions.php:

    remove_filter(‘get_the_excerpt’, ‘wp_trim_excerpt’);

    add_filter(‘get_the_excerpt’, ‘custom_trim_excerpt’);

    function custom_trim_excerpt($text = ”)

    {

    $raw_excerpt = $text;

    if ( ” == $text ) {

    $text = get_the_content(”);

    //$text = strip_shortcodes( $text );

    $text = apply_filters(‘the_content’, $text);

    $text = str_replace(‘]]>’, ‘]]>’, $text);

    $excerpt_length = apply_filters(‘excerpt_length’, 300);

    $excerpt_more = apply_filters(‘excerpt_more’, ‘ ‘ . ‘[…]’);

    $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );

    }

    return apply_filters(‘wp_trim_excerpt’, $text, $raw_excerpt);

    }

    add_filter(‘get_the_excerpt’,’do_shortcode’);

    Doing the above, I’m able to write in the excerpt shortcodes as [wp_eStore_product_details id=1 info=”description”] and [wp_eStore_product_details id=1 info=”price”] or [wp_eStore_product_details id=5 info=”available_copies”].

    They work out fine.

    Instead, if I add the shortcode [wp_eStore_add_to_cart id=1] it breaks the blog page.

    Any help?

    June 30, 2014 at 11:07 pm #30325
    admin
    Keymaster

    Normally you would just need to add that one line of code and it will do that trick. In your case, it looks like your theme is using a custom excerpt function so thats where the issue is I think. What version of eStore plugin are you using?

    June 30, 2014 at 11:46 pm #30326
    dgitaly
    Member

    I have updated the eStore plugin last decembre (version 7.0.2) and the Extra Shortcodes version is 4.7.8

    As for the theme, I’m using the Super Spark Theme by Goodlayers.

    Do you think that that’s the issue?

    July 1, 2014 at 12:35 am #30327
    admin
    Keymaster

    okay the plugin version looks fine but I would still recommend doing the following:

    https://support.tipsandtricks-hq.com/forums/topic/re-install-or-load-a-fresh-build-of-the-plugins

    Also, it is worth doing the theme test mentioned below:

    https://support.tipsandtricks-hq.com/forums/topic/test-to-identy-a-conflicting-theme-or-plugin

    July 1, 2014 at 12:35 pm #30328
    dgitaly
    Member

    Thank you for prompt reply.

    Eventually I’ve done as suggested:

    1. deactivated all the plugins

    2. tried Twentyfourteen theme

    As results, I can now confirm that the issue is a custom excerpt superspark theme function and the problem is not related to the WP eStore Plugin or eventual conflicts with other plugins.

    To solve my issue I’ve requested help to GoodLayers staff for the superspark theme has a conflict with wp estore plugin.

    Hope to find a quick solution.

    Grazie again, dina

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Log In

Forum Related

  • Forum Home
  • Forum Search
  • Forum Registration
  • Forum Login

Support Related Forms

  • Contact Us
  • Customer Support
  • Request a Plugin Update
  • Request Fresh Download Links

Useful Links

  • Plugin Upgrade Instructions
  • WP eStore Documentation
  • WP eMember Documentation
  • WP Affiliate Platform Documentation
  • Tips and Tricks HQ Home Page
  • Our Projects

Quick Setup Video Tutorials

  • WP eStore Video Tutorial
  • WP eMember Video Tutorial
  • WP Affiliate Platform Video Tutorial
  • Lightbox Ultimate Video Tutorial

Our Other Plugins

  • WP Express Checkout
  • Stripe Payments Plugin
  • Simple Shopping Cart Plugin
  • Simple Download Monitor

Copyright © 2025 | Tips and Tricks HQ