Weglot с WordPress и Woocommerce

У нас есть сайт WP с Woocommerce, и мы переводим контент с помощью Weglog. Кажется, все работает нормально, кроме описания вариантов продукта.

Я думаю, проблема в том, что варианты хранятся как значения данных в форме:

<form class="variations_form cart" action="XXXXX" method="post" enctype="multipart/form-data" data-product_id="64161" data-product_variations="[{&quot;attributes&quot;:{&quot;attribute_pa_color1&quot;:&quot;rose-gold-plattiert&quot;},&quot;availability_html&quot;:&quot;<p class=\&quot;stock available-on-backorder\&quot;>Dieser Artikel ist beim Hersteller verf\u00fcgbar. Lieferung innerhalb von 14 Tagen<\/p>\n&quot;,&quot;backorders_allowed&quot;:true,&quot;dimensions&quot;:{&quot;length&quot;:&quot;&quot;,&quot;width&quot;:&quot;&quot;,&quot;height&quot;:&quot;&quot;},&quot;dimensions_html&quot;:&quot;n.a.&quot;,&quot;display_price&quot;:25,&quot;display_regular_price&quot;:25,&quot;image&quot;:{&quot;title&quot;:&quot;MEL-VP04RG12000_gr&quot;,&quot;caption&quot;:&quot;&quot;,&quot;,&quot;variation_description&quot;:&quot;<p>Vivid Anh\u00e4nger f\u00fcr Halsketten | Drop,Ros\u00e9 Gold plattiert |Edelstahl<\/p>\n&quot;,&quot;variation_id&quot;:64163,&quot;variation_is_active&quot;:true,&quot;variation_is_visible&quot;:true,&quot;weight&quot;:&quot;&quot;,&quot;weight_html&quot;:&quot;n.a.&quot;,&quot;jck_additional_images&quot;" current-image="51586">

В Weglog есть хук для переводов, который я должен использовать: https://developers.weglot.com/wordpress/filters/translations-filters

Я не могу заставить его работать, потому что я не достаточно опытен. Я хотел бы иметь возможность переводить различные текстовые элементы с этим.

Спасибо заранее.


person sixtynine    schedule 24.10.2020    source источник


Ответы (1)


Решение:

add_filter( 'weglot_get_regex_checkers', 'custom_weglot_add_regex_checkers' );
function custom_weglot_add_regex_checkers( $regex_checkers ) {

// Text
$regex_checkers[] = new \Weglot\Parser\Check\Regex\RegexChecker( '#data-product_variations="([^"]*)"#', 'JSON', 1, array('attributes'), "html_entity_decode" , "htmlentities" );

return $regex_checkers;

}

person sixtynine    schedule 25.10.2020