Woocommerce best_selling_products shortcode not working - wordpress

Trying to add:
<?php echo do_shortcode('[products best_selling="true" limit="4"]'); ?>
In a template returns nothing. I see that no hooks are present for this but woocommerce says it should be supported.

Please Try this shortcode
[best_selling_products per_page="12"]
Please refer below link for Woocommerce Shortcodes
https://docs.woocommerce.com/document/woocommerce-shortcodes/

Coming back to this one because I came across another shortcode that wasn't working.
It turned out that the theme was the culprit. After switching to the default theme all shortcodes were working correctly.

Related

Elementor says - "Sorry, the content area was not found in your page. " while using custom shortcode

I am using default theme of Elementor Plugin. Plugin is very nice but I am facing issue while using my custom shortcode in page. It shows “Sorry, the content area was not found in your page. You must call
the_content function in the current template, in order for Elementor to work on this page.”
[1]: https://i.stack.imgur.com/7xBHV.png
To solve this error, I have added <?php the_content(); ?> in my custom shortcode but it shows the same error.
I have also tried by creating a custom template, but the result is same.
So please help me to solve this error. Any suggestions are acceptable.
Thanks in Advance
Probably your shortcode function changes the post query.
try adding wp_reset_query(); before the function closes.

Wordpress shortcodes working in php but not in text editor

I seem to be having a problem outputting shortcodes from the wordpress text editor. The shortcodes work fine when echoing from php but it is only in the text editor they simply produce what is written.
I have added the following lines to my functions.php:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But this has no effect. This is happening across multiple plugins. Does anyone know why this might be happening?
Thanks!
So I've solved this. I figured out that this was only happening on custom templates. I then queried that issue and found that you have to use the_content() function to extract the content within your custom template and have shortcodes work. This is because the_content() parses the content in a manner that will make your shortcodes work.

woocommerce theme development without shortcodes

I was wondering if someone could help me out. I am developing a theme that uses woocommerce as the ecommerce solution. I know that there are predefined shortcodes that you can use but i was wondering if there was a way to actually implement woocommerce items in my php code as opposed to using shortcodes.
Thanks,
Try this:
https://wordpress.stackexchange.com/a/125286/60175
<?php echo do_shortcode('[product_page id="31"]'); ?>
And at the Shortcodes doc, I see
To find the Product ID, go to the Product > Edit screen and look in the URL for the postid= as shown below.
http://docs.woothemes.com/document/woocommerce-shortcodes/
Of course this still uses shortcodes (pretty slick), but in your PHP. The Wordpress framework must be available in your PHP page, which I think you do by including wp-load.php at the beginning.

How to use wordpress shortcode in template

I need help with wordpress shortcode. I have written shortcode function in functions.php in my theme files. Now I create page in wordpress administration and then I need to place this shortcode into special place in my theme but with content which I wrote in administration.
I hope that you understand what I mean.
Thank you for your help.
In your template code:
<?php echo do_shortcode('[your-shortcode]'); ?>
Replace [your-shortcode] with whatever your shortcode is, including parameters/attributes and/or closing tags if required.

Wordpress plugin shortscodes in other plugins?

I'm developing a plugin that creates custom wordpress pages, however I ran into a problem when trying to get shortcodes from other plugins to integrate into my plugin, well more like I couldn't find any info on it.
For example if someone uses my custom page builder and adds a short code [gallery] that is associated with an enabled plugin, I want the shortcode to do it's thing.
Could anyone point me in the right direction for this?
Try wordpress
http://wordpress.org/plugins/synved-shortcodes/
while this plugin let's you integrate shortcodes on every wordpress page , I suppose that you issue is with wordpress functions.php file where you can have a look at , with this plugin installed !
You can check if a shortcode exist before printing it with the function shortcode_exists() (https://codex.wordpress.org/Function_Reference/shortcode_exists)
Example:
<?php
if ( shortcode_exists( 'gallery' ) ) {
// The [gallery] short code exists.
}
?>
Then, if it exist and you want to print that shortcode with PHP code you should use do_shortcode() function (https://developer.wordpress.org/reference/functions/do_shortcode/)
Example:
<?php echo do_shortcode('[gallery]); ?>
Always use in WordPress's in-built
the_content
hook to print your custom page content.
WordPress by default process all shortcodes before outputting any stuff from this hook.
More info can be found here: https://codex.wordpress.org/Function_Reference/the_content

Resources