AI Verified

Name

auto delete woocommerce product images

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

14/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

auto delete woocommerce product images

 
                    
1add_action( 'before_delete_post', 'wwidilo_autodelete_product_images', 10, 1 );
2function widilo_autodelete_product_images( $post_id )
3{
4 $product = wc_get_product( $post_id );
5 //check if the post is a product
6 if ( !$product ) {
7 return;
8 }
9 //get product images by id
10 $featured_image_id = $product->get_image_id();
11 $image_galleries_id = $product->get_gallery_image_ids();
12 //delete featured product image
13 if( !empty( $featured_image_id ) ) {
14 wp_delete_post( $featured_image_id );
15 }
16 //delete image galleries
17 if( !empty( $image_galleries_id ) ) {
18 foreach( $image_galleries_id as $single_image_id ) {
19 wp_delete_post( $single_image_id );
20 }
21 }
22}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

1

WooCommerce Custom Content Under New Order Email Heading

Added: 1 year ago

Last Updated: 1 day ago

As you know, editing the WooCommerce template core files is a big fat no-no for security and update purposes. If you need to make edits to the emails, you’re much better off doing this by targeting th...

WooCommerce

AI Verified

1

WooCommerce Product Preview Link

Added: 1 year ago

Last Updated: 2 months ago

Long story short, this solution shows a button on the single product template which links to a URL of your choice. If you leave the custom field empty, the button will not show. Now, we’re a big fan o...

WooCommerce

AI Verified

0

Show Order Histories on User Profiles at the Backend

Added: 1 year ago

Last Updated: 1 year ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

3

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 day ago

WooCommerce

AI Verified

3

Redirect customers to own thank-you page after order

Added: 1 year ago

Last Updated: 1 day ago

You may want to redirect your customers to a custom thank you page after they place an order. You can do that with the following WooCommerce snippet

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago