I have enqueued the JS file to my WordPress plugin using :PHP
public function enqueue_scripts() {
wp_enqueue_script('my_awesome_plugin', plugins_url( '../assets/main.js', __FILE__), NULL, NULL, true );
}
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
I have a function called addedToCart() on that file : JS
addedToCart(){
console.log("Added to Cart");
}
I need to call that function once a user added to his cart. I can use this hook : PHP
add_action( 'woocommerce_add_to_cart', array( $this, 'add_to_cart' ), 10, 6 );
public function add_to_cart($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data)
{
?>
<script>
//What code should I add <-- Line
<script>
<?PHP
}
What code should I write to call that function on the JS File?
Thanks for your time.