Created
July 29, 2022 14:34
-
-
Save marcusig/dcc88b9abb762d72923a260b8dcd9111 to your computer and use it in GitHub Desktop.
Gtranslate Pro editor filter for the product configurator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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