I want to use WooCommerce but instead of buying from the site, the visitor will be redirected in Amazon. I want to change the "Add to Cart" href attribute with a URL specified in each product as a special attribute. I managed to get this working but the code seems a little bit messy- plus I had to change the plugin code - . Is there a way to make this in a more "proper" way?
我想使用WooCommerce,但不是从网站上购买,访问者将被重定向到亚马逊。我想将每个产品中指定的URL更改为“添加到购物车”href属性作为特殊属性。我设法让这个工作,但代码似乎有点凌乱 - 加上我不得不改变插件代码 - 。有没有办法以更“正确”的方式做到这一点?
<?php $meta = get_post_meta( get_the_ID(),'_product_attributes' );?>
<a class="btn single_add_to_cart_button button alt" href="<?php echo $meta[0]['amazon_url']['value']?> ">Buy from Amazon</a>
1 个解决方案
#1
WooCommerce has this already set up with the "External/Affiliate Product" setting for your product.
WooCommerce已经为您的产品设置了“外部/联盟产品”设置。
See this video on YouTube for an example or View Woo's documentation and video
有关示例或View Woo的文档和视频,请在YouTube上观看此视频
In short, you put in the product URL after selecting the External/Affiliate Product dropdown option (single product is the default) and then you can customize the Add to cart text.
简而言之,您在选择“外部/会员产品”下拉选项(单个产品是默认选项)后输入产品URL,然后您可以自定义“添加到购物车”文本。
#1
WooCommerce has this already set up with the "External/Affiliate Product" setting for your product.
WooCommerce已经为您的产品设置了“外部/联盟产品”设置。
See this video on YouTube for an example or View Woo's documentation and video
有关示例或View Woo的文档和视频,请在YouTube上观看此视频
In short, you put in the product URL after selecting the External/Affiliate Product dropdown option (single product is the default) and then you can customize the Add to cart text.
简而言之,您在选择“外部/会员产品”下拉选项(单个产品是默认选项)后输入产品URL,然后您可以自定义“添加到购物车”文本。