要删除产品类别中所有已注册的'thumbnail_id',您可以使用此功能运行一次 . Make a backup before . (此功能仅适用于管理员用户角色) .
这是代码:
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();
2 回答
要删除产品类别中所有已注册的'thumbnail_id',您可以使用此功能运行一次 . Make a backup before . (此功能仅适用于管理员用户角色) .
这是代码:
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
浏览站点的任何页面(后端或前端)以运行脚本 . 现在您可以删除此代码 .
do_action( 'woocommerce_before_subcategory_title', $category );
这会将category_thumbnail添加到产品类别中,现在您可以做一些事情,强制它返回空白 .所以删除此动作调用 .
同
或者只是通过覆盖
content-product_cat.php
模板注释掉do_action( 'woocommerce_before_subcategory_title', $category );
.