Skip to content

Instantly share code, notes, and snippets.

@marcusig
Created July 29, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusig/dcc88b9abb762d72923a260b8dcd9111 to your computer and use it in GitHub Desktop.
Save marcusig/dcc88b9abb762d72923a260b8dcd9111 to your computer and use it in GitHub Desktop.
Gtranslate Pro editor filter for the product configurator
<?php
add_filter( 'mkl_pc_get_configurator_data_js_output', function( $js, $id, $data ) {
if ( class_exists( 'GTranslate' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
$output = 'var PC = PC || {};'."\n";
$output .= 'PC.productData = PC.productData || {};'."\n";
// Add compatibility with GTranslate premium, enabling users to manually update translations.
$output .= "fetch('/wp-admin/admin-ajax.php?action=pc_get_data&data=init&fe=".$_REQUEST['fe']."&id={$id}&ver=".time()."').then(r => r.json()).then(data => {PC.productData.prod_$id = data;});";
return $output;
}
return $js;
}, 20, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment