Woocommerce商店页面(类别页面模板)添加到购物车按钮行为

时间:2018-03-27 10:42:35

标签: php wordpress woocommerce

我试图让类别页面(商店页面)拥有链接到单个产品页面而不是标准[添加到购物车]行为的自定义按钮。

以下是我的代码,但是主题定义的按钮上的链接定义了带有链接变量add_action('woocommerce_after_shop_loop_item','replace_add_to_cart'); function replace_add_to_cart() { global $product; $link = $product->get_permalink(); echo do_shortcode('[us_btn text="Details" link="' . $link . '" size="12px" align="right" icon="fal|info-circle"]'); 的短代码。但是,不是将用户带到单个产品页面,而是将用户带回到同一个打开的商店页面。

我做错了什么?

#TabsBar {
	padding: 0px 12px; /*Like TopBanner*/
	height: 40px; /*TopBanner height*/
	width: calc(100% - 24px); /* to compensate for the padding*/
	background-color: blue;
	margin-bottom: 8px;
	overflow: hidden;
}

.Tabs {
	background-color: transparent;
	border: hidden;
	font-size: 120%;
	font-weight: bold;
	color: white;
	display: inline-block;
	padding: 0px 20px;
}

.HeightInherit {
	height: inherit;
}

@media (max-width: 320px) {
  .Tabs { 
    display: block; 
    width: 100%;
    }
   #TabsBar {
     height: auto;
   }
}

2 个答案:

答案 0 :(得分:0)

如果您的链接href已填充产品网址,请检查您的开发人员工具,如果它返回到同一页面,则可能为空。 如果短代码没有很好地渲染,那么它必须是问题。

答案 1 :(得分:0)

必须从链接中删除http://

echo do_shortcode('[us_btn text="Details" link="url:' . str_replace("http://", "", $link) . '" size="12px" align="right" icon="fas|info-circle"]');