Forked from trueqap/del_woo_products_with_ attachment.php
Created
August 15, 2018 17:27
-
-
Save tallesairan/026996b687f8ab32aa8c5ac24ee31a90 to your computer and use it in GitHub Desktop.
Delete WooCommerce products with images (attachment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function delete_associated_media( $id ) { | |
$media = get_children( array( | |
'post_parent' => $id, | |
'post_type' => 'attachment' | |
) ); | |
if( empty( $media ) ) { | |
return; | |
} | |
foreach( $media as $file ) { | |
wp_delete_attachment( $file->ID ); | |
} | |
} | |
add_action( 'before_delete_post', 'delete_associated_media' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment