有沒有將縮略圖選項設置爲none的方法,適用於所有WooCommerce類別?取消在WooCommerce中設置所有產品類別縮略圖
我不得不從超過400個類別中刪除縮略圖,並做一個接一個將帶我的方式比時間更是我要...
我想從我的媒體庫中刪除圖像,但現在在我的類別中沒有佔位符圖像,它只是在管理編輯產品類別頁面上的圖像中顯示「縮略圖」。
我不知道這是否是一個PHP,SQL,或者插件的問題,但我願意嘗試一下任。
感謝
有沒有將縮略圖選項設置爲none的方法,適用於所有WooCommerce類別?取消在WooCommerce中設置所有產品類別縮略圖
我不得不從超過400個類別中刪除縮略圖,並做一個接一個將帶我的方式比時間更是我要...
我想從我的媒體庫中刪除圖像,但現在在我的類別中沒有佔位符圖像,它只是在管理編輯產品類別頁面上的圖像中顯示「縮略圖」。
我不知道這是否是一個PHP,SQL,或者插件的問題,但我願意嘗試一下任。
感謝
要刪除產品類別中所有已註冊的'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文件或也以任何插件文件。
瀏覽您網站的任何頁面(後端或前端)以運行該腳本。現在你可以刪除這段代碼。
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);
。
工作就像一個魅力,謝謝! ** ** LoicTheLifesaver –