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

Question

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.

0
what ever 1 year 2022-02-20T15:23:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse