在 WooCommerce 中取消设置所有产品类别缩略图
Unset all product categories thumbnail in WooCommerce
有没有办法将所有 WooCommerce 类别的缩略图选项设置为 none?
我必须从 400 多个类别中删除缩略图,一个一个地删除会花费我很多时间...
我尝试从我的媒体库中删除图像,但现在我的类别中没有占位符图像,它只是在管理员编辑产品类别页面上的图像中显示 "thumbnail"。
我不确定这是 PHP、SQL 还是插件问题,但我愿意尝试其中任何一个。
谢谢
do_action( 'woocommerce_before_subcategory_title', $category );
这会将 category_thumbnail 添加到产品类别,现在您可以做一些事情,强制它 return 为空。
因此删除此操作调用。
add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
和
remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
或者通过覆盖 content-product_cat.php
模板注释掉 do_action( 'woocommerce_before_subcategory_title', $category );
。
要删除所有已注册的 'thumbnail_id' 在您的产品类别中,您可以使用此功能成为 运行 一次。 在之前做好备份。 (此功能仅适用于管理员用户角色)。
代码如下:
function remove_product_categories_thumbnail_id()
{
// Working only for admin user roles
if( ! current_user_can( 'administrator' ) ) : return;
global $wpdb;
$table_termmeta = $wpdb->prefix . "termmeta";
$table_term_taxo = $wpdb->prefix . "term_taxonomy";
# Get ALL related Product category WP_Term objects (that have a thumbnail set)
$results = $wpdb->get_results( "
SELECT * FROM $table_termmeta
INNER JOIN $table_term_taxo ON $table_termmeta.term_id = $table_term_taxo.term_id
WHERE $table_termmeta.meta_key LIKE 'thumbnail_id'
AND $table_term_taxo.taxonomy LIKE 'product_cat'
");
// Storing all table rows ID related Product category (that have a thumbnail set)
foreach($results as $result)
$meta_ids_arr[] = $result->meta_id;
// Convert the arry in a coma separated string of IDs
$meta_ids_str = implode( ',', $meta_ids_arr );
# DELETE ALL thumbmails IDs from Product Categories
$wpdb->query( "
DELETE FROM $table_termmeta
WHERE $table_termmeta.meta_id IN ($meta_ids_str)
");
}
## RUN THE FUNCTION ONCE ##
remove_product_categories_thumbnail_id();
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
浏览您网站的任何页面(后端或前端)以 运行 脚本。现在您可以删除此代码了。
有没有办法将所有 WooCommerce 类别的缩略图选项设置为 none?
我必须从 400 多个类别中删除缩略图,一个一个地删除会花费我很多时间...
我尝试从我的媒体库中删除图像,但现在我的类别中没有占位符图像,它只是在管理员编辑产品类别页面上的图像中显示 "thumbnail"。
我不确定这是 PHP、SQL 还是插件问题,但我愿意尝试其中任何一个。
谢谢
do_action( 'woocommerce_before_subcategory_title', $category );
这会将 category_thumbnail 添加到产品类别,现在您可以做一些事情,强制它 return 为空。
因此删除此操作调用。
add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
和
remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
或者通过覆盖 content-product_cat.php
模板注释掉 do_action( 'woocommerce_before_subcategory_title', $category );
。
要删除所有已注册的 'thumbnail_id' 在您的产品类别中,您可以使用此功能成为 运行 一次。 在之前做好备份。 (此功能仅适用于管理员用户角色)。
代码如下:
function remove_product_categories_thumbnail_id()
{
// Working only for admin user roles
if( ! current_user_can( 'administrator' ) ) : return;
global $wpdb;
$table_termmeta = $wpdb->prefix . "termmeta";
$table_term_taxo = $wpdb->prefix . "term_taxonomy";
# Get ALL related Product category WP_Term objects (that have a thumbnail set)
$results = $wpdb->get_results( "
SELECT * FROM $table_termmeta
INNER JOIN $table_term_taxo ON $table_termmeta.term_id = $table_term_taxo.term_id
WHERE $table_termmeta.meta_key LIKE 'thumbnail_id'
AND $table_term_taxo.taxonomy LIKE 'product_cat'
");
// Storing all table rows ID related Product category (that have a thumbnail set)
foreach($results as $result)
$meta_ids_arr[] = $result->meta_id;
// Convert the arry in a coma separated string of IDs
$meta_ids_str = implode( ',', $meta_ids_arr );
# DELETE ALL thumbmails IDs from Product Categories
$wpdb->query( "
DELETE FROM $table_termmeta
WHERE $table_termmeta.meta_id IN ($meta_ids_str)
");
}
## RUN THE FUNCTION ONCE ##
remove_product_categories_thumbnail_id();
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
浏览您网站的任何页面(后端或前端)以 运行 脚本。现在您可以删除此代码了。