[CYS on Core] Add the sample product badge before the product name to mark placeholder products. (#45691)

* Add the sample badge to dummy products on the main products list.

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Patricia Hillebrandt 2024-03-19 17:51:38 +01:00 committed by GitHub
parent 8631fb5d48
commit 2fc83cbe85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Add the sample product badge before the product name to mark placeholder products.

View File

@ -40,6 +40,7 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
add_filter( 'views_edit-product', array( $this, 'product_views' ) );
add_filter( 'get_search_query', array( $this, 'search_label' ) );
add_filter( 'posts_clauses', array( $this, 'posts_clauses' ), 10, 2 );
add_action( 'manage_product_posts_custom_column', array( $this, 'add_sample_product_badge' ), 9, 2 );
}
/**
@ -658,4 +659,19 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
return $pieces;
}
/**
* Add a sample product badge to the product list table.
*
* @param string $column_name Column name.
* @param int $post_id Post ID.
*
* @since 8.8.0
*/
public function add_sample_product_badge( $column_name, $post_id ) {
$is_sample_product = 'product' === get_post_type( $post_id ) && get_post_meta( $post_id, '_headstart_post', true );
if ( $is_sample_product && 'name' === $column_name ) {
echo '<span class="sample-product-badge" style="margin-right: 6px;border-radius: 4px; background: #F6F7F7; padding: 4px; color: #3C434A;font-size: 12px;font-style: normal;font-weight: 400;line-height: 16px; height: 24px;">' . esc_html__( 'Sample', 'woocommerce' ) . '</span>';
}
}
}