'Wordpress Custom Add To Cart Button with AJAX

i made a custom add to cart button but i cant load it with ajax here is the code.

i added this code into my functions.php

// Add "Add To Cart" button  //
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button2', 13 );
function add_a_custom_button2() {
    global $product;

    // Not for variable and grouped products that doesn't have an "add to cart" button
    if( $product->is_type('variable') || $product->is_type('grouped') ) return;

    // Output the custom button linked to the product
    echo '<div style="margin-bottom:10px;">
        <a class="customviewaddtocartbutton" href="' . esc_attr( $product->add_to_cart_url() ) . '">' . __('Add To Cart') . '</a>
    </div>';
}

can anyone help me please, Thank You <3



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source