[英]How to get 'add to cart button' to appear where I place it
我现在有这段代码,它在我的 woocommerce 网站上的“添加到购物车”按钮之后添加了一个按钮。 这是我在网上找到的一段代码。
add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart_10', 20 );
function additional_simple_add_to_cart_10() {
global $product;
// Only for variable product type
$href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=10';
$class = 'ingle_add_to_cart_button-10 button alt';
$style = 'display: inline-block; margin-top: 12px;';
$button_text = __( "10 Tickets", "woocommerce" );
// Output
echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';
}
我想编辑它,以便按钮移动到我在页面上放置此代码的任何位置,只需要一个通用按钮,将 10 个单位添加到购物车 - 因为它目前会在添加到购物车后自动放置。
您可以使用 WordPress 中的短代码 function 为您的 function additional_simple_add_to_cart_10 创建一个短代码。 这是示例:
add_shortcode('add-to-cart', 'additional_simple_add_to_cart_10');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.