2017-07-28 250 views
0

有没有将缩略图选项设置为none的方法,适用于所有WooCommerce类别?取消在WooCommerce中设置所有产品类别缩略图

我不得不从超过400个类别中删除缩略图,并做一个接一个将带我的方式比时间更是我要...

我想从我的媒体库中删除图像,但现在在我的类别中没有占位符图像,它只是在管理编辑产品类别页面上的图像中显示“缩略图”。

enter image description here

我不知道这是否是一个PHP,SQL,或者插件的问题,但我愿意尝试一下任。

感谢

回答

1

要删除产品类别中所有已注册的'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文件或也以任何插件文件。

浏览您网站的任何页面(后端或前端)以运行该脚本。现在你可以删除这段代码。

+0

工作就像一个魅力,谢谢! ** ** LoicTheLifesaver –

0

do_action('woocommerce_before_subcategory_title', $category);这增加category_thumbnail产品类别,现在你可以做几件事情,迫使它返回空。

如此删除此操作调用。

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);

相关问题