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, 4 months ago by dgitaly.
-
AuthorPosts
-
March 17, 2011 at 5:07 pm #2974dangermooseSpectator
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 #30316dangermooseSpectatorOr maybe I could add the add to cart shortcode to a custom field?
March 18, 2011 at 12:13 am #30317amin007ParticipantBy 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 #30318dangermooseSpectatorThanks 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 #30319amin007ParticipantThat 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 #30320dangermooseSpectatorMany 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 #30321toolanceMemberHi 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 #30322amin007ParticipantAs 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 #30323dgitalyMemberHello,
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 #30324dgitalyMemberHello 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 #30325adminKeymasterNormally 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 #30326dgitalyMemberI 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 #30327adminKeymasterokay 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 #30328dgitalyMemberThank 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
-
AuthorPosts
- You must be logged in to reply to this topic.