Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function testing_atts_wpml() {
- global $product;
- $product_id = 68; // Example product ID
- $product = wc_get_product($product_id);
- // Get the translated product ID and object
- $ru_product_id = apply_filters('wpml_object_id', $product_id, 'product', true, 'ru');
- $ru_product = wc_get_product($ru_product_id);
- // Get translated description and title
- $ru_description = $ru_product->get_description();
- $ru_title = $ru_product->get_title();
- // Initialize the output HTML
- $param_val = "<div><h2>" . $ru_title . "</h2><p>" . $ru_description . "</p><table><tr><th>Taxonomy ID</th><th>Taxonomy name</th><th>Translated taxonomy name</th><th>Translated attribute value</th></tr>";
- // Iterate over attributes
- $attributes = $ru_product->get_attributes();
- foreach ($attributes as $attribute) {
- $taxonomy = $attribute->get_name();
- $taxonomy_name = wc_attribute_label( $taxonomy );
- // Assuming attribute is a taxonomy
- if ($attribute->is_taxonomy()) {
- $translated_taxonomy_name = apply_filters('wpml_translate_single_string', $taxonomy_name, 'WordPress', 'Product attribute name', 'ru');
- $attribute_values = $ru_product->get_attribute($taxonomy);
- } else {
- // For custom attributes, this approach may vary
- $translated_taxonomy_name = $taxonomy_name; // Custom attributes might not have a taxonomy name
- $attribute_values = $attribute->get_data()['value']; // Directly get the value for custom attributes
- }
- $param_val .= "<tr><td>" . $attribute->get_id() . "</td><td>" . $taxonomy . "</td><td>" . $translated_taxonomy_name . "</td><td>" . $attribute_values . "</td></tr>";
- }
- $param_val .= '</table></div>';
- return $param_val;
- }
- add_shortcode('testing_atts_wpml', 'testing_atts_wpml');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement