Php 取消设置WooCommerce中的所有产品类别缩略图
是否有办法将所有类别的缩略图选项设置为“无” 我必须从400多个类别中删除缩略图,一个接一个的删除会花费我更多的时间 我尝试从我的媒体库中删除这些图像,但现在我的类别中没有占位符图像,它只是在“管理编辑产品类别”页面的图像中显示“缩略图” 我不确定这是PHP、SQL还是插件问题,但我愿意尝试其中任何一种 感谢Php 取消设置WooCommerce中的所有产品类别缩略图,php,wordpress,woocommerce,thumbnails,categories,Php,Wordpress,Woocommerce,Thumbnails,Categories,是否有办法将所有类别的缩略图选项设置为“无” 我必须从400多个类别中删除缩略图,一个接一个的删除会花费我更多的时间 我尝试从我的媒体库中删除这些图像,但现在我的类别中没有占位符图像,它只是在“管理编辑产品类别”页面的图像中显示“缩略图” 我不确定这是PHP、SQL还是插件问题,但我愿意尝试其中任何一种 感谢do\u action('woocommerce\u在子类别\u title'之前,$category)这会将category_缩略图添加到产品类别中,现在您可以做一些事情,强制它返回空
do\u action('woocommerce\u在子类别\u title'之前,$category)
这会将category_缩略图添加到产品类别中,现在您可以做一些事情,强制它返回空
因此,请删除此操作调用
add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
与
或者只是注释掉
do\u action('woocommerce\u在子类别\u title'之前,$category)
通过覆盖content-product_cat.php
模板。要删除产品类别中所有注册的“缩略图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文件或任何插件文件中
浏览站点的任何页面(后端或前端)以运行脚本。现在您可以删除此代码
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();