how to display woocommerce product tags on single product page.? - wordpress

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').

Related

Preventing search engines from indexing all posts

I'm working on a Wordpress site where I'm using the posts to create a list of tour dates for an entertainer. With ACF I have fields set up in a table and the client just enters a date, location, link to buy tickets, etc.
The table is all I need visitors to see. The actual post created by single.php is not going to be styled and should never be seen.
I want to prevent someone searching the artist and city and coming across the post.
Is there a plugin or a disallow I can put in the robot.txt file?
Any help is appreciated. Kinda funny in a time where everyone is trying to get noticed by search engines and I want to hide something from them!
Add the code below to your themes functions.php:
add_action('wp_head', 'your_prefix_noindex_nofollow');
function your_prefix_noindex_nofollow() {
if(is_single()){
echo '<meta name="robots" content="noindex,nofollow"/>';
}
}
You can also change "your_prefix" in the function name to whatever you like. It will work as is, but it's a good practice to use the same prefix in all your function names.

WooCommerce Shop page : Customize sorting dropdown to product categories dropdown

I would like to modify the products sorting on the shop page to product categories filter where the user can select the browse the products of categories from there.
I am a rookie in programming. I checked the WooCommerce directory to find the .php file I should work on. I got some clue it is in archive-product.php but I don't see the code which display the sorting dropdown.
Can anyone give me some clue to achieve this ? Or is there any workaround ? Thanks.
I added this in functions.php :
// remove default sorting dropdown
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// now add the new dropdown
add_action( 'woocommerce_before_shop_loop', 'add_product_category_dropdown' );
function add_product_category_dropdown(){
print '<span class="woocommerce-ordering">'; // So it takes the same position as the default dropdown
the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' );
print '</span>';
}
The reason you wouldn't see the code is that majority of what is generated by Woocommerce is handled by actions and hooks. In easier terms this means Woocommerce creates functions that spits out content and assigns them to different areas of the website.(For more information on Woocommerce actions and hooks, read here - https://docs.woothemes.com/document/introduction-to-hooks-actions-and-filters/ )
I'd recommend using the plugin below. It does exactly what you seem to be asking for and you can avoid having to play in parts you might not be comfortable with yet.
https://wordpress.org/plugins/yith-woocommerce-ajax-navigation/
Most awesome thing is that it's not one of those plugins that force you to get premium to actually get the desired effect.
I just found the solution few days ago. I use the function of WooCommerce product categories widget on the shop page.
This line of code will output the dropdown of product categories:
<?php the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' ); ?>

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.

Display Variation Price woocommerce when all prices are equal

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.

Wordpress: How to pass additional Content to the blog-preview page?

For each blog-post on my wordpress-blog I'd like to have Teaxtarea where i can pass additional content for that post.
In my case that would be an unordered list which contains a quick overview of the content.
That additional content should be displayed in the preview of the post on the blog-preview-page.
My problem:
I am actually not sure on how to best add this additional content and then pass it to the preview.
Do I use wordpress' custom fields for something like this?
I'm gratefull for a push in the right direction.
Thank you,
Nils
If I understand you right, I'd take a look at "custom meta boxes" functionality - it allows you to add any type of additional input into your blog post admin area, and than display its content on front-end however you like.
There's a nice tutorial series on that topic, with example code snippets:
http://wp.tutsplus.com/series/reusable-custom-meta-boxes/
And if you'd like to display the textarea content only in preview mode, you can use appropriate conditional tag in you template file:
http://codex.wordpress.org/Conditional_Tags#A_Preview
The conditional tag is_preview returns true when a single post is viewed in Draft mode. The following will append post meta to the content when a post is being previewed:
function so16799607_preview( $content )
{
if ( ! is_preview() )
return $content;
return $content . get_post_meta( get_the_ID(), 'my_post_meta', true );
}
add_filter( 'the_content', 'so16799607_preview', 10, 1 );
You should check out Advanced Custom Fields. That's a really stable plugin that lets you create custom meta boxes in posts, pages and custom post types. That plugin does exactly what your question states. Need al little PHP to get stuff from your database, but that is as easy as:
<?php the_field(field_name);?>
And the documentation is pretty good. And if you don't like a plugin, it exports the PHP as well.
Anther tool that does the same is Pods Framework. Both powerfull extensions to any WP install in my opinion.
Hope this helps.

Resources