Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Automatically Delete Woocommerce Images After Deleting a Product

add_action( 'before_delete_post', 'delete_product_images', 10, 1 );

function delete_product_images( $post_id )
{
    $product = wc_get_product( $post_id );

    if ( !$product ) {
        return;
    }

    $featured_image_id = $product->get_image_id();
    $image_galleries_id = $product->get_gallery_image_ids();

    if( !empty( $featured_image_id ) ) {
        wp_delete_post( $featured_image_id );
    }

    if( !empty( $image_galleries_id ) ) {
        foreach( $image_galleries_id as $single_image_id ) {
            wp_delete_post( $single_image_id );
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: dump php array into javascript array 
Php :: laravel 8 try catch 
Php :: update user role wordpress 
Php :: Unable to create PsySH runtime directory. Make sure PHP is able to write to /run/user in order to continue. 
Php :: yii2 gridview filter exact value 
Php :: laravel mass update 
Php :: php createFromFormat day of week 
Php :: phpspreadsheet set cell by column and row 
Php :: how to rename uploaded file in codeigniter before upload 
Php :: push key value array php 
Php :: how make custom menu in wordpress 
Php :: php compare two arrays of objects 
Php :: carbon get day name from date 
Php :: how to completely delete php 
Php :: php group multidimensional array by value 
Php :: php even odd program 
Php :: php code to generate strong password 
Php :: php round to the nearest 10 
Php :: compare php date with mysql date 
Php :: Adding data to a laravel collection 
Php :: env value return null laravel 
Php :: php calculate days of a month 
Php :: model get last query in php 
Php :: insert data using model in laravel 8 
Php :: laravel csrf error 419 
Php :: laravel 7 eloquent on delete set null schema 
Php :: laravel add user 
Php :: php migrate comand 
Php :: wordpress get id from page title 
Php :: php is int 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =