【发布时间】:2017-01-23 00:28:53
【问题描述】:
我想在我的 woocommerce 产品描述页面末尾添加第二个添加到购物车按钮。 我该怎么做?
非常感谢您的宝贵时间!
【问题讨论】:
标签: wordpress woocommerce
我想在我的 woocommerce 产品描述页面末尾添加第二个添加到购物车按钮。 我该怎么做?
非常感谢您的宝贵时间!
【问题讨论】:
标签: wordpress woocommerce
方法一
$id = get_the_ID();
echo do_shortcode( '[add_to_cart id='.$id.']' );
方法二
$product = get_product(get_the_ID());
echo "<a href='".$product->add_to_cart_url()."'>add to cart</a>";
请您在 woocommerce 产品描述的代码末尾添加上面的代码吗?
方法3
在您的活动主题functions.php中添加以下代码。
add_action( 'woocommerce_single_product_summary', 'custom_button_after_product_summary', 30 );
function custom_button_after_product_summary() {
global $product;
echo "<a href='".$product->add_to_cart_url()."'>add to cart</a>";
}
【讨论】:
1.解决方案: 在你的主题的 function.php 文件中添加代码。
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );
function my_extra_button_on_product_page() {
global $product;
echo '<a href="URL">Add to cart</a>';
}
2。解决方案: 安装自定义 WooCommerce 添加到购物车插件
Custom WooCommerce Add to Cart Plugin
3.解决方案: 您可以使用带有短代码的钩子:
或者在您自己的模板中为 WooCommerce 文件创建覆盖。
【讨论】:
解决方案:在您的活动主题中添加代码functions.php.
// Add "Add To Cart" button //
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button2', 13 );
function add_a_custom_button2() {
global $product;
// Not for variable and grouped products that doesn't have an "add to cart" button
if( $product->is_type('variable') || $product->is_type('grouped') ) return;
// Output the custom button linked to the product
echo '<div style="margin-bottom:10px;">
<a class="customviewaddtocartbutton" href="' . esc_attr( $product->add_to_cart_url() ) . '">' . __('Add To Cart') . '</a>
</div>';
}
样式:在您的child-theme.css 或theme.css 中添加代码
/* Custom Add To Cart Button */
.customviewaddtocartbutton {
display: block !important;
width: 100% !important;
border: none !important;
background-color: #E6723F !important;
color: white !important;
padding: 2px 2px !important;
font-size: 16px !important;
cursor: pointer !important;
text-align: center !important;
border-radius: 30px !important;
}
.customviewaddtocartbutton:hover {
background-color: #246e4c !important;
color: white !important;
cursor: pointer !important;
}
【讨论】: