I encountered a situation that I did not understand the reason for. I add the shortcode I created to the product short description, but it is displayed twice on the product page. Moreover, even though I add it after the explanation, it shows before the explanation. What is the reason for this error? Or where am I doing wrong? https://ibb.co/ZmDrXrH
https://ibb.co/Lt4VqZV
add_shortcode('test-shortcode', 'ws_frontend_product_page_validate');
function ws_frontend_product_page_validate() {
echo 'TEST TEST TEST';
}
Related
I'm trying to pre-fill the short description when adding a new product. I've figured out how to do it with the main description as shown below, but cannot figure out the short description.
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "This is some custom content I'm adding to the post editor because I hate re-typing it.";
return $content;
}
I'm suspecting it is similar but with a different hook instead of "default_content" any ideas?
Figured it out. After reading around I realized that Woocommerce uses WordPress's excerpt for the short description. So after some trial and error I found that the hook I was looking for is "default_excerpt". Does the trick!
This is sample url-https://www.inoventary.com/product/ipega-wireless-bluetooth-gamepad/
single product page on woocommerce store is showing only header and footer , not showing product or single product page template .
Log Error -2018-06-12T17:15:39+00:00 CRITICAL Call to undefined function dhvc_woo_get_product_formatted_name()
I don't know how to fix , your answer is very much appreciated
Seems like your theme is overriding default woocommerce template and there is some function being used which is not found.
You can do following:
Take fresh copy of single-product folder from wp-content/plugins/woocommerce/templates and upload that in your theme's woocommerce folder
Looking at name of undefined function, it shows that this function might have been there only for formatting product title, so if you don't want to follow step 1 then just trace this function in your code and comment it out.
Let me know if it helps
I'm looking like a crazy person if there is a way to display the tags of a product on the single product page with woocommerce ( wordpress plugin). I can not find anything about ti and I've been trying to tweak the code, but without success . . .
if anybody has some high lite, it will be wonderful,
thank you very much
Ok, so depending on the WordPress theme you use, they might show automatically (just checked and it works right away with the "official" Storefront theme).
If you're writing a plugin (or a theme) though, you're most likely to want the PHP solution. In that case, according to this, you should be good to go with the following:
global $product; // gets the Product object (correspoding to the single page)
$product->get_tags( $product ); // returns an array with product tags
According to this post, you have to use get_terms('product_tag').
So I'm working on a store in woocommerce and we want the variation price (that displays just above the add cart button) to be the only one on the page, and we've discovered if a variable product has the same price for all variations it won't show the price down there, does anyone have a solution for this?
I know this question was asked almost a year ago, but this has been a "problem" in WooCommerce for much longer, so I'm posting this answer for reference.
In actual fact this is meant to be a performance/memory enhancement feature to avoid rendering and processing duplicated variation data in the HTML data attribute. But it ends up causing issues because it results in the HTML output of variations not being consistent from product to product. Really this whole issue is due to bad practices being used by WooCommerce to render the dynamic content for the variations, but what can you do...
This! (in PHP 5.3+, which you really should be using these days)
add_filter('woocommerce_available_variation', function($available_variations, \WC_Product_Variable $variable, \WC_Product_Variation $variation) {
if (empty($available_variations['price_html'])) {
$available_variations['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
}
return $available_variations;
}, 10, 3);
For those who don't know, you simply need to add this to your theme's functions.php file, or any other PHP file that loads before the template files.
I asked this question over in the actual tutorial, but not sure I'll get an answer anytime soon as it's almost 2 months old... so I'll take a gander here...
Tutorial is here: Build a WordPress Plugin to Add Author Biographies to your Posts
To sum up the tutorial and what the problem is, The tutorial adds an Author Bio on to the end of the content like so (the short version):
function x($content) {
return $content . "Author Bio";
}
add_action('the_content','x');
The Problem:
When someone uses:
$z = apply_filters('the_content', 'some content here');
echo $z;
The Author Bio will end up applied to $z and if $z is echoed out in the middle of some page… the Author Bio would be in the middle of some page… correct? (it's correct because I've tested it...)
Is there a better way to apply something to the end/under/below the_content hook? other than add_action(‘the_content’, ‘some_function’) because this to me seems evil...
or is apply_filters(‘the_content’, ‘some content here’) not the norm or something developers shouldn't be using inside their WordPress templates…? (which seems pretty much the norm, at least upon Google-ing formatting "the_content" outside the loop)...
Using apply_filters('the_content','some content here'), while it may not be 'the norm' (I don't know. I haven't seen it before, but if I needed formatted text, that's what I'd do), is a perfectly valid use of filters to get some text formatted like the content. Unfortunately, there's no better way to append something to content from a plugin. That is just the way these things work.
However, there's a (less than optimal) way of circumventing this. As part of the setup/install process for your plugin, have the user insert a custom function call, action, or filter into their theme. I know several plugins that do this, so it's not all that uncommon. Something like this:
do_action('my_super_awesome_bio_hook');
Would allow you to hook in without worrying about adding a bio to unexpected (and unintended) content. Even better would be inserting a filter:
echo apply_filters('my_super_awesome_bio_filter_hook','');
That would allow your plugin to modify the bio, but also allow the one using the plugin to override it if necessary (like on pages where they're just using excerpts, like search results, etc.).
Hope this helped.
Also, one minor addendum: you should be using add_filter, not add_action to append the Author Bio. add_action still works, but it's a filter you want to be using.
I bumped into a similar issue with a widget I'm dev'ing. I just found this:
http://codex.wordpress.org/Function_Reference/wpautop
Which I'm now going to use instead of add_filters('the_content'). I want the WYSIWYG formatting but I don't want things append to my content because it's not traditional content anymore.