I'm currently working on a WooCommerce theme and attempting to add a sidebar to the product detail page.
I've been able to get the sidebar added (specifically, this one: http://woocommerce.wp-a2z.org/oik_file/templatescontent-widget-product-php/)
Now, I'm trying to figure out how to add a class of "active" to the currently selected product and can't seem to figure it out?
In other words, how do I do something along the lines of if the current product id is equal to the product id in the sidebar add class="active" to the li?
I've made numerous searches and haven't been able to come up with anything useful, so I'm turning here.
Any help greatly appreciated!!
Retrieve the ID of the current item in the WordPress Loop.
hence works for the product id too. #tested #woo-commerce
Since WooCommerce
2.2
you are able to simply use thewc_get_product
Method. As an argument you can pass theID
or simply leave it empty if you're already in the loop.wc_get_product()->get_id();
OR with 2 lines
2017 Update:
Woocommerce doesn't like you accessing those variables directly. This will get rid of any warnings from woocommerce if your wp_debug is true.
If the query hasn't been modified by a plugin for some reason, you should be able to get a single product page's "id" via
OR
EDIT: As of WooCommerce 3.0 this needs to be
your can query woocommerce programatically you can even add a product to your shopping cart. I'm sure you can figure out how to interact with woocommerce cart once you read the code. how to interact with woocommerce cart programatically
====================================
Save the current product id before entering your loop:
Then in your loop for your sidebar, use $product->id again to compare: