我现在有这个代码,它在我的wooccommerce网站上的"添加到购物车"按钮后面添加了一个按钮。这是我在网上找到的一段代码。
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的短代码函数为您的函数additional_simple_add_to_cart_10创建一个短代码。下面是一个例子:
add_shortcode('add-to-cart', 'additional_simple_add_to_cart_10');