Woocommerce - Get SKU in product single page - wordpress

I want go get the SKU in my product single pages in Woocommerce. I tried <?php get_sku(); ?> which is a featured function according to the Woocommerce docs (http://docs.woothemes.com/wc-apidocs/class-WC_Product.html) but it will just break the loop. What to do?

get_sku() is a method of the WC_Product class, so you need to have a product on which to call it, like this:
<?php echo $product->get_sku(); ?>
This should work if you are inside the WooCommerce product loop, and is what is used in the WooCommerce template files. If you don't already have a reference to the product object, you may need to add the following line at the top of the file in order to access it:
global $product;

Related

Products filtered by specific product attribute value in Woocommerce

I have a problem with woocommerce shortcodes. I have products on backend side but after upgrading woocommerce to latest version (3.3.5) I noticed that shortcodes are not same anymore. I used to query product by attribute with [product_attributes] shortcode. According to woocommerce docs this shortcode is turned on [products] with attributes.
This is my shortcode:
<?php echo do_shortcode('[products attribute="collezione_chakra" terms="stella" limit="-1"]'); ?>
As you can see stella attribute has 3 products and also the taxonomy is correct (I think), as you can see here below.
I've also tried using pa_ as taxonomy prefix as you can see below, but not working
<?php echo do_shortcode('[products attribute="pa_collezione_chakra" terms="stella" limit="-1"]'); ?>
What is going wrong? Thanks in advance.

Add shortcode to woocommerce product short description

I'm trying to add a shortcode that will be placed on all single product posts. Specifically on the product's short description. I went to woocommerce templates and found a file "short-description" and I tried placed following code, but it's not working:
<?php echo do_shortcode("[wpqr-code]"); ?>
This shortcode is to supposed to generate and display a qr code on each product post where it is placed.
I found a solution if anyone needs. Place this code in functions.phpfile:
add_action( 'woocommerce_before_add_to_cart_form', 'enfold_customization_extra_product_content', 15 );
function enfold_customization_extra_product_content() {
echo do_shortcode("[wpqr-code]");
}

advanced-custom-fields the_field function not work in wordpress

I'm trying to use the the_field(); function in wordpress but did't work
also I tried to use the get_field(); function and same problem what I can do
<?php the_field('contact_form_short_code'); ?>
I am using advanced-custom-fields plugin the free version
the_field('contact_form_short_code') will try to get the field info from the current post in the loop. If you're not currently in a loop it will look to the current page/post.
If you want to reference a post from outside the loop you must specify the post ID, eg: the_field('contact_form_short_code', $post_id)
Hope that helps
Check if your field group location points to your template, taxonomy or custom post type, after that try to use echo to call your field.
Check this link www.advancedcustomfields.com
If you want to display the shortcode (contact_form_short_code) specified in the admin panel via a custom field (ACF), you need to use the do_shortcode(); function.
In your case, the code looks like this:
<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"]
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>

woo commerce - how to show custom fields on published page

I have set 2 custom fields on the wordpress / woocommerce product page called "imballo" and "sottoimballo" with their values. How do I display these on the published page?
Thanks!
You would have to display the custom fields in the WooCommerce Single Product Page template,
You could do it in two ways,
Add a code in an existing hook of the Product Single page. Check hooks here
Modify the template by overriding it in your WordPress theme. Read here
And in the place where you want to display do the following,
<?php
//Please add your HTML structure as needed.
echo get_post_meta(get_the_ID(), 'imballo');
echo get_post_meta(get_the_ID(), 'sottoimballo');
?>

include link list depending on category

I want to display the linklist widget only on a certain category.
The current way the sidebar is fetched is:
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(1))
Which doesnt give me a say in the calling of the links widget. If i put an if clause there, then the rest of the widgets dont get loaded.
So i either need to customize the links widget it self or find a way to call the links widget directly?
And how do i check which category i'm on?
You can call an indivdual widget by using Conditional Tags « WordPress Codex, like this:
<?php if (in_category('1')) { ?> call widget here
<?php } ?>
Or (haven't used this myself) load widgets by category, etc: WordPress › Dynamic Widgets « WordPress Plugins
To print the Category you are on use the_category(' ');
Example :<p>Categories: <?php the_category(' '); ?></p>
Also have a look at the Documentation http://codex.wordpress.org/Template_Tags/the_category

Resources