Last active
January 14, 2022 14:33
-
-
Save FrancoStino/68137f5adce283f33335de9d3b901931 to your computer and use it in GitHub Desktop.
Additional Products Table Column (Gallery) and Display List of Products With No Gallery @ Admin All Product - WooCommerce
This file contains hidden or 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
<? | |
/** | |
* @snippet Products Table Column Gallery @ WooCommerce Admin | |
*/ | |
add_filter( 'manage_edit-product_columns', 'bbloomer_admin_products_visibility_column', 9999 ); | |
function bbloomer_admin_products_visibility_column( $columns ){ | |
$columns['galleria'] = 'Galleria'; | |
return $columns; | |
} | |
add_action( 'manage_product_posts_custom_column', 'bbloomer_admin_products_visibility_column_content', 10, 2 ); | |
function bbloomer_admin_products_visibility_column_content( $column ){ | |
global $product; | |
if ( $column == 'galleria' ) { | |
$attachment_ids = $product->get_gallery_image_ids(); | |
if(count ($attachment_ids) > 0 ) { ## Check if image gallery exist | |
foreach( $attachment_ids as $attachment_id ) { | |
/* Display the image URL */ | |
// echo $Original_image_url = wp_get_attachment_url( $attachment_id ); | |
/* Display Image instead of URL */ | |
add_image_size( 'thumbnail_prodotti_colonna_galleria', 30, 30, true ); ## Custom image size | |
echo wp_get_attachment_image($attachment_id, 'thumbnail_prodotti_colonna_galleria'); | |
} | |
}else{ | |
echo 'NON ESISTE'; | |
} | |
} | |
} | |
/** | |
* @snippet Display List of Products With No Gallery Image @ WP Dashboard > Products | |
*/ | |
add_action( 'admin_notices', 'products_no_weight_admin' ); | |
function products_no_weight_admin(){ | |
global $pagenow, $typenow; | |
if ( 'edit.php' === $pagenow && 'product' === $typenow ) { | |
echo '<div class="notice notice-warning is-dismissible"> <h3 class="dashicons-before dashicons-warning">PRODOTTI SENZA GALLERIA DI IMMAGINI</h3><ul>'; | |
$args = array( | |
'status' => 'publish', | |
'visibility' => 'visible', | |
'limit' => -1 | |
); | |
$products = wc_get_products( $args ); | |
foreach ( $products as $product ) { | |
if ( ! $product->get_gallery_image_ids() ) { | |
echo '<li><a href="' . esc_url( get_edit_post_link( $product->get_id() ) ) . '">' . $product->get_name() . '</a> | Link: '. esc_url( get_post_permalink( $product->get_id() ) ) . '</li>'; | |
} | |
} | |
echo '</ul></div>'; | |
} | |
} | |
/* ----- */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment