Home > Software engineering >  Is it possible disable button 'Add to cart' when point insufficient
Is it possible disable button 'Add to cart' when point insufficient

Time:07-21

I want to ask everyone to know about WooCommerce WordPress. I have a page for list product WooCommerce, in there have information like title and price and button "Add to cart" when the cursor hovers to the product. I want to disable or hide the button when my point is insufficient for the product. Is it possible to do that? I am using plugin GamiPress - WooCommerce Points Gateway for payment with points

Above this example for a product (100 points)

enter image description here

Above this my current point (0 point)

enter image description here

CodePudding user response:

$point = 0;
if($point == 0){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
}

CodePudding user response:

You can add the disabled attribute on the button if points are insufficient for the product. For example, you can get the total points in the var pints and if the points are less than 100 you add disable attribute to the button.

var point;
if(point<100 ){
$('.add-to-cart').attr('disabled');


}
  • Related