【发布时间】:2019-02-25 00:09:50
【问题描述】:
我需要客户能够在添加到购物车和继续购物和添加到购物车和重新定向到结帐之间进行选择。换句话说,我在产品页面上添加了一个额外的按钮。
作为 WooCommerce 的新手,我正在努力让数量输入发挥作用。如果只购买一个,效果很好,但添加多个(数量)时就不行了。
另外,我不明白如何添加对可变产品的支持,但这可能是一个单独的问题? (对不起)。
这是我正在使用的代码:
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );
function add_content_after_addtocart() {
$current_product_id = get_the_ID();
$product = wc_get_product( $current_product_id );
$checkout_url = WC()->cart->get_checkout_url();
if( $product->is_type( 'simple' )) { ?>
<script>
jQuery(function($) {
$(".custom-checkout-btn").on("click", function() {
$(this).attr("href", function() {
return this.href + '&quantity=' + $('input.qty').val();
});
});
});
</script>
<?php
echo '<a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="single_add_to_cart_button button alt">Buy & Checkout</a>';
}
}
任何关于我哪里出错的意见?感谢我能得到的所有帮助。
【问题讨论】:
标签: php jquery wordpress woocommerce product