Woocommerce,获取当前产品ID [英] Woocommerce, get current product id

查看:526
本文介绍了Woocommerce,获取当前产品ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究WooCommerce主题,并试图将侧边栏添加到产品详细信息页面.

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?

换句话说,如果当前产品ID等于边栏中的产品ID,我该如何做呢?在li中添加class ="active"?

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!!

推荐答案

2017年更新-自WooCommerce 3起:

2017 Update - since WooCommerce 3:

global $product;
$id = $product->get_id();

Woocommerce不喜欢您直接访问这些变量.如果您的wp_debug为true,这将消除woocommerce发出的任何警告.

Woocommerce doesn't like you accessing those variables directly. This will get rid of any warnings from woocommerce if your wp_debug is true.

这篇关于Woocommerce,获取当前产品ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆