首页 文章

在WooCommerce中取消设置所有产品类别缩略图

提问于
浏览
0

对于所有WooCommerce类别,有没有办法将缩略图选项设置为无?

我必须从400个类别中删除缩略图并逐一进行,这将比我想要的时间更多...

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

enter image description here

我不确定这是PHP,SQL还是插件问题,但我愿意尝试其中任何一个 .

谢谢

2 回答

  • 1

    要删除产品类别中所有已注册的'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();
    

    代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .

    浏览站点的任何页面(后端或前端)以运行脚本 . 现在您可以删除此代码 .

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

相关问题