我正在尝试使用qty字段将WooCommerce添加到购物车短信代码中。我的代码工作正常,但点击添加到购物车没有显示消息/通知。如何添加此请帮助。还有如何在没有重新加载页面的情况下实现这一点,例如商店/存档页面添加到购物车按钮。
function elm_add_to_cart_shortcode(){
global $product;
$_product_id = 655;
$elm_html = '';
if(class_exists('Woocommerce')) {
if ( ! is_shop() && ! is_product_taxonomy() ) {
//Start Construct the shortcode html output
ob_start();
$elm_html .= '<div class="elm_add_to_cart_wrp">';
$elm_html .= '<form class="cart" method="post" enctype="multipart/form-data">';
$elm_html .= '<div class="elm_quantity quantity buttons_added"><input type="button" value="-" class="minus">';
$elm_html .= '<input type="number" class="input-text qty text" step="1" min="1" max="" name="quantity" value="1" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric">';
$elm_html .= '<input type="button" value="+" class="plus">';
$elm_html .= '</div>';
$elm_html .= '<button type="submit" name="add-to-cart" value='.$_product_id.' class="elm_button fusion-button button-default button-large single_add_to_cart_button button alt">Add to cart</button>';
$elm_html .= '</form>';
$elm_html .= '</form>';
return $elm_html ;
ob_end_clean();
}
//==========================================================
wc_enqueue_js( "
jQuery( '.add_to_cart_inline .qty' ).on( 'change', function() {
var qty = jQuery( this ),
atc = jQuery( this ).next( '.add_to_cart_button' );
atc.attr( 'data-quantity', qty.val() );
});
" );
//==========================================================
}
}
add_shortcode('elmaddtocart','elm_add_to_cart_shortcode');