Add shortcode to woocommerce product short description - wordpress

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]");
}

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.

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' ); ?>

How to add an "add to cart" button in single-product.php page in woocommerce?

I am using woocommerce to develop a ecommerce site
In single-product.php I am facing a problem.
I can't display the add to cart button under the product in this page.
So far I am using this code:
<?php
//global $post;
echo do_shortcode('[add_to_cart id="$post->ID"]');
?>
But no luck for me yet!
Maybe you made a simple writing mistake? Try this:
<?php
echo do_shortcode('[add_to_cart id="'.$post->ID.'"]');
?>
I would suggest using the WooCommerce default content-single-product.php template.
By default, the single product's add to cart template is added via the woocommerce_template_single_add_to_cart() function and is added to the woocommerce_single_product_summary hook (priority 30).
If you must change the single product content very radically, you can either call woocommerce_template_single_add_to_cart() directly or add it to a different hook. There's no reason to use a shortcode here.
If I understood you right, you want to move the Add-to-Cart button from the top of the page to the bottom of the page, so that it would go below the main product description.
Here is how I've done this on my website:
/* Removing the Add-To-Cart button from right below the product summary.
*/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
/* Adding the Add-To-Cart button so that it would go after the main product description.
*/
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart', 12 );

Woocommerce - Get SKU in product single page

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;

Change meta description in search result page using add_action / add_filter

I trying to change the meta description on single template and page template, and it works.
I trigger to change meta description by using add_action. But when I try to change meta description on search result page, this is not work by using add_action.
Is there any other way to to so? I need using add_action or add_filter because I will trigger the meta description from bottom of the page.
It would be easier if you added this to your header.php
<?php if (is_search())
{
//ADD SUM META DESCRIPTIONS
}
?>

Resources