admin管理员组文章数量:1390204
I need to create notification when user's added quantity is reaching item's quantity. This is working function without ajax.
add_action( 'woocommerce_single_product_summary', 'bbloomer_show_return_policy', 40 );
function bbloomer_show_return_policy() {
global $product;
global $woocommerce;
$idP = $product->get_id();
foreach ( $woocommerce->cart->get_cart() as $cart_item ) {
if($cart_item['product_id'] == $idP ){
$qty = $cart_item['quantity'];
break; // stop the loop if product is found
}
}
if($qty >= $product->get_stock_quantity())
{
echo 'notification';
}
}
How can I achieve that notification will throw when user added extra quantity of item.
Also, I tried to make ajax call, but item's cart quantity still the same.
add_action('wp_head', 'ajx_action_javascript_wp');
function ajx_action_javascript_wp() {
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
jQuery("body").on("click", ".single_add_to_cart_button", function(event){
<?php
global $product;
global $woocommerce;
$idP = $product->get_id();
foreach ( $woocommerce->cart->get_cart() as $cart_item ) {
if($cart_item['product_id'] == $idP ){
$qty = $cart_item['quantity'];
echo $qty;
break;
}
}
?>
var mydata = <?php echo $qty; ?>;
var data = {
action: 'custom_action',
//whatever: 1234,
qTY: mydata
};
console.log(data);
});
});
</script>
<?php
}
What I'm doing wrong?
本文标签: woocommerce offtopicPass values to ajax
版权声明:本文标题:woocommerce offtopic - Pass values to ajax 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744582657a2614014.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论