Using wordpress plugin "Code Snippets" – How could I take a php function like the one below and turn it into an Ajax button inside of elementor?
Essentially… i’d really like to know how I can take any PHP function and execute it from an Ajax button.
Thanks so much for your help! Clearly I have no idea what I’m taking about.
Function:
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
2
Answers
you can put the php function inside a php file and do a ajax call to execute the php script and you can use the response data like below:
You need to checkout the code here I created the admin hook to clear the cart using ajax