Count when a post of a custom post type is deleted and store it in a theme option

I work on a website that shows products in a catalogue without checkout. Those products can be bougth stationary, and then the product will be deleted from a custom post type. So, I basically want to count all deleted posts of a certain post type, add them to a theme option value, and then update the theme option value with the new value. I thought of something like this:

function getSoldProductsCount() {

    $addCount                  = 0;
    $oldCount                  = get_option( 'sold_products_count', 'number' );
    $newCount                  = $oldCount + $addCount;

    /*
    * Here I want to do something like: for each deleted post of posttype 'product', increase the counter value by 1
    */

    return 'span class=sold-products-count'. $newCount .'/span';
    update_option( 'sold_products_count', $newCount );
}

add_shortcode( 'sold_products_count', __NAMESPACE__ . '\\getSoldProductsCount' );

Now I am stuck here, because I don't know which hook I should use to increase my counter. Ist there a possibility to count all delete actions of a certain custom post type? Sorry if the question is silly, I am very new to Wordpress.

Topic theme-options hooks Wordpress

Category Web


The hook played by WordPress just before a post is "definitively" deleted is https://developer.wordpress.org/reference/hooks/delete_post/

+the comment left by @tom-j-nowell.

Regards

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.