【问题标题】:Adding a "return to shop" button on single product pages that leads back to product parent category在单个产品页面上添加“返回商店”按钮,返回产品父类别
【发布时间】:2016-07-11 12:55:16
【问题描述】:

我的客户希望在 WooCommerce 中的单个产品页面上放置一个“返回商店”按钮,该按钮可以返回上一页,而不是主商店页面。

我已经解释过所有浏览器都有后退按钮,但他们对拥有这个按钮是死心塌地。我什至提到过激活面包屑,但他们也不喜欢那些。

我怎样才能做到这一点。 非常感谢任何帮助。

【问题讨论】:

标签: php wordpress woocommerce categories product


【解决方案1】:

您将使用下面的代码获取类别 id,然后添加 if 条件以显示类似

$product_category = wp_get_post_terms( $post->ID, 'product_cat' );

【讨论】:

  • 能否请您准备好使用代码。一个只需要复制和粘贴。或者至少给我一些使用上述代码的提示。谢谢。
  • 我使用了这个代码<?php $product_category = wp_get_post_terms( $post->ID, 'product_cat' ); $category_id = get_cat_ID( $product_category ); $category_link = get_category_link( $category_id ); ?> <a href="<?php echo esc_url( $category_link ); ?>" class="btn btn-default btn-lg manage-btn " role="button" title="Return">Return</a>,但我得到的是产品的网址而不是类别的网址。你能告诉我吗?谢谢!
猜你喜欢
  • 2018-12-16
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 2018-07-23
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多