wpml_set_element_language_details
Fires after element language details are set, allowing customization of translation language information.
add_action( 'wpml_set_element_language_details', $callback, 10, 1 );
Description
Fires after language details for a WPML element are set. Developers can use this to perform custom actions or modify the language association for posts, terms, or other WPML-supported elements. It's primarily for internal WPML use.
Usage
add_action( 'wpml_set_element_language_details', 'your_function_name', 10, 1 );
Parameters
-
$language_args(mixed) - This parameter contains an array of arguments that specify the details for setting an element's language in WPML.
Examples
<?php
/**
* Example function to hook into wpml_set_element_language_details.
*
* This function demonstrates how to access and potentially modify
* the language details of a WordPress element being set by WPML.
*
* @param array $language_args An array containing language details for the element.
* Expected keys: 'element_id', 'element_type', 'trid',
* 'language_code', 'source_language_code'.
*/
function my_custom_wpml_set_element_language_details( $language_args ) {
// Check if the necessary keys exist in the arguments.
if ( ! isset( $language_args['element_id'], $language_args['element_type'], $language_args['language_code'] ) ) {
// Log an error or return if essential arguments are missing.
error_log( 'WPML set element language details called with incomplete arguments.' );
return;
}
$element_id = $language_args['element_id'];
$element_type = $language_args['element_type'];
$language_code = $language_args['language_code'];
$trid = isset( $language_args['trid'] ) ? $language_args['trid'] : null;
$source_lang = isset( $language_args['source_language_code'] ) ? $language_args['source_language_code'] : null;
// Example: Log the details being set for a specific element type.
if ( 'post_product' === $element_type ) {
$product_id = $element_id;
$post_type = explode( '_', $element_type )[1]; // Extract 'product'
// You could perform actions here, like updating custom meta based on language.
// For demonstration, we'll just log the information.
error_log( sprintf(
'WPML setting language for %s ID %d: Target Language "%s", Translation ID "%s", Source Language "%s"',
$post_type,
$product_id,
$language_code,
$trid ? $trid : 'N/A',
$source_lang ? $source_lang : 'N/A'
) );
// Example: If the source language is English, and we're translating to Spanish,
// maybe we want to add a specific tag or category to the Spanish product.
if ( 'en' === $source_lang && 'es' === $language_code ) {
// wp_set_post_terms( $product_id, array( 'español' ), 'product_cat' );
// add_post_meta( $product_id, '_custom_translated_from_en', true, true );
}
}
// If this were a filter, you would need to return the modified or original $language_args.
// For this action hook, we don't typically return anything unless modifying the array
// and expecting subsequent handlers to use the modified version, which is less common
// for this specific hook.
}
add_action( 'wpml_set_element_language_details', 'my_custom_wpml_set_element_language_details', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/woocommerce/woocommerce-license.php:1027
'element_id' => $group_id,
'element_type' => 'post_' . $type,
'trid' => $trid,
'language_code' => $language_code,
'source_language_code' => null,
);
do_action( 'wpml_set_element_language_details', $language_args );
}
$courses_linked = apply_filters( 'ulgm_license_group_courses_linked_in_order', $courses_linked, $group_id, $this );
if ( $courses_linked ) {
foreach ( $courses_linked as $course_id ) {
$course_id = apply_filters( 'ulgm_license_group_linked_course_id', $course_id, $group_id, $this );