@alisa.bahringer
You can change the WooCommerce category thumbnail using php by adding the following code to your theme's functions.php file:
1 2 3 4 5 6 7 8 9 10 11 |
function change_category_thumbnail($thumbnail_id, $term_id, $taxonomy) {
$thumbnail_url = 'URL_OF_YOUR_NEW_THUMBNAIL'; // Replace with the URL of your new thumbnail
// Set the new thumbnail for the category
update_woocommerce_term_meta($term_id, 'thumbnail_id', $thumbnail_id);
// Set the new thumbnail URL for the category
update_woocommerce_term_meta($term_id, 'thumbnail_id', $thumbnail_url);
}
add_action('created_term', 'change_category_thumbnail', 10, 3);
add_action('edited_term', 'change_category_thumbnail', 10, 3);
|
Make sure to replace URL_OF_YOUR_NEW_THUMBNAIL with the actual URL of your new thumbnail image.
This code uses the created_term and edited_term actions to update the category thumbnail whenever a new category is created or an existing category is edited. The update_woocommerce_term_meta() function is used to update the category's thumbnail ID and URL.
Remember to save the changes and update your theme for the changes to take effect.
@alisa.bahringer
Вы можете изменить миниатюру категории WooCommerce с помощью php, добавив следующий код в functions.php вашей темы:
1 2 3 4 5 6 7 8 9 10 11 |
function change_category_thumbnail($thumbnail_id, $term_id, $taxonomy) {
$thumbnail_url = 'URL_ВАШЕЙ_НОВОЙ_МИНИАТЮРЫ'; // Замените на URL вашей новой миниатюры
// Установите новую миниатюру для категории
update_woocommerce_term_meta($term_id, 'thumbnail_id', $thumbnail_id);
// Установите новый URL миниатюры для категории
update_woocommerce_term_meta($term_id, 'thumbnail_id', $thumbnail_url);
}
add_action('created_term', 'change_category_thumbnail', 10, 3);
add_action('edited_term', 'change_category_thumbnail', 10, 3);
|
Убедитесь, что заменили 'URL_ВАШЕЙ_НОВОЙ_МИНИАТЮРЫ' на фактический URL вашего изображения для новой миниатюры.Этот код использует действия created_term и edited_term для обновления миниатюры категории при создании новой категории или редактировании существующей категории. Функция update_woocommerce_term_meta() используется для обновления идентификатора и URL миниатюры категории.Не забудьте сохранить изменения и обновить тему для вступления изменения в силу.