Я пытаюсь динамически предварительно заполнить описание продукта и краткое описание в WooCommerce на основе настраиваемого поля выбора ACF (расширенные настраиваемые поля). Поле позволяет пользователю выбрать один из двух вариантов: «Грузовик» и «Строительная машина». В зависимости от выбора я хочу заполнить описания продуктов конкретным содержанием. Настройка поля ACF
Я создал поле выбора в ACF с именем Machine_type со следующими параметрами:
Грузовик
Строительная машина
Показ группы полей ACF Текущий код
Я успешно заполнил описания новых продуктов, используя этот код:
function prefill_product_description_new() {
global $post;
// Only add pre-filled content for new products
if ($post->post_type == 'product' && $post->post_status == 'auto-draft') {
?>
jQuery(document).ready(function($) {
// Check if the product description is empty and pre-fill it
if ($('#content').val() === '') {
$('#content').val('
This is a default product description for new products.
');
}
// Check if the short description is empty and pre-fill it
if ($('#excerpt').val() === '') {
$('#excerpt').val('This is a default short product description.');
}
});
jQuery(document).ready(function($) {
// Set default content if the description is empty
if ($('#content').val() === '') {
$('#content').val('
This is a default product description for new products.
');
}
// Listen for the change in the machine type dropdown
$('#acf-field_66e994151813').on('change', function() {
var machineType = $(this).val(); // Get the selected machine type
// Check if machine type value is logged correctly
if (machineType === 'Truck') {
$('#content').val('
[b]Truck Description Template[/b]
...');
} else if (machineType === 'Construction Machine') {
$('#content').val('
[b]Construction Machine Description Template[/b]
...');
}
});
});
Подробнее здесь: [url]https://stackoverflow.com/questions/78994807/how-to-pre-fill-woocommerce-product-descriptions-based-on-acf-field-selection[/url]
Я пытаюсь динамически предварительно заполнить описание продукта и краткое описание в WooCommerce на основе настраиваемого поля выбора ACF (расширенные настраиваемые поля). Поле позволяет пользователю выбрать один из двух вариантов: «Грузовик» и «Строительная машина». В зависимости от выбора я хочу заполнить описания продуктов конкретным содержанием. [b]Настройка поля ACF[/b] Я создал поле выбора в ACF с именем Machine_type со следующими параметрами: [list] [*]Грузовик Строительная машина [/list] Показ группы полей ACF [b]Текущий код[/b] Я успешно заполнил описания новых продуктов, используя этот код: [code]function prefill_product_description_new() { global $post;
// Only add pre-filled content for new products if ($post->post_type == 'product' && $post->post_status == 'auto-draft') { ?>
jQuery(document).ready(function($) { // Check if the product description is empty and pre-fill it if ($('#content').val() === '') { $('#content').val(' This is a default product description for new products. '); } // Check if the short description is empty and pre-fill it if ($('#excerpt').val() === '') { $('#excerpt').val('This is a default short product description.'); } });
jQuery(document).ready(function($) { // Set default content if the description is empty if ($('#content').val() === '') { $('#content').val(' This is a default product description for new products. '); }
// Listen for the change in the machine type dropdown $('#acf-field_66e994151813').on('change', function() { var machineType = $(this).val(); // Get the selected machine type
// Check if machine type value is logged correctly if (machineType === 'Truck') { $('#content').val(' [b]Truck Description Template[/b] ...'); } else if (machineType === 'Construction Machine') { $('#content').val(' [b]Construction Machine Description Template[/b] ...'); } }); });