From 2fc83cbe85ae70ca861b10f5172d9a80329fd5c7 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Tue, 19 Mar 2024 17:51:38 +0100 Subject: [PATCH] [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 --- ...the-product-name-to-mark-placeholder-products | 4 ++++ .../class-wc-admin-list-table-products.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 plugins/woocommerce/changelog/45691-45690-cys-on-core-add-the-sample-product-badge-before-the-product-name-to-mark-placeholder-products diff --git a/plugins/woocommerce/changelog/45691-45690-cys-on-core-add-the-sample-product-badge-before-the-product-name-to-mark-placeholder-products b/plugins/woocommerce/changelog/45691-45690-cys-on-core-add-the-sample-product-badge-before-the-product-name-to-mark-placeholder-products new file mode 100644 index 00000000000..92a1e62b845 --- /dev/null +++ b/plugins/woocommerce/changelog/45691-45690-cys-on-core-add-the-sample-product-badge-before-the-product-name-to-mark-placeholder-products @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Add the sample product badge before the product name to mark placeholder products. \ No newline at end of file diff --git a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php index 73c58f160b6..628fce7af66 100644 --- a/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php +++ b/plugins/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-products.php @@ -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 '' . esc_html__( 'Sample', 'woocommerce' ) . ''; + } + } }