• For some reason my action hook function is not firing at all. I am almost 100% I have done it correctly, yet it won’t fire when the user clicks ‘Cancel’ under My Account.

    My code which is placed in functions.php:

    add_action( 'cancelled_subscription', 'cancelsub', 10, 2 );
    
    function cancelsub($user_id, $subscription_key)
    {
    	$servername = "localhost";
    	$username = "root";
    	$password = "pass";
    	$dbname = "rsrs";
    
    	// Create connection
    	$conn = new mysqli($servername, $username, $password, $dbname);
    	// Check connection
    	if ($conn->connect_error) {
    		die("Connection failed: " . $conn->connect_error);
    	} 
    
    	$sql = "UPDATE users SET status = 'pending cancellation' WHERE subscription_id = '$subscription_key'";
    
    	if ($conn->query($sql) === TRUE) {
    		echo "Record updated successfully";
    	} else {
    		echo "Error updating record: " . $conn->error;
    	}
    
    	$conn->close();
    }
  • The topic ‘[Plugin: Woocommerce subscriptions] Cancelled sub action hook not firing’ is closed to new replies.