Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 5 replies, has 2 voices.

Last updated by Laura 2 years, 1 month ago.

Assigned support staff: Laura.

Author Posts
December 19, 2018 at 11:10 pm #3018327

John

Tell us what you are trying to do? I've just add the following code and on other languages it doesn't the correct atribute

Is there any documentation that you are following?

function isa_woocommerce_all_pa(){
  
    global $product;
    $attributes = $product->get_attributes();
  
    if ( ! $attributes ) {
        return;
    }
  
    $out = '<ul class="custom-attributes">';
  
    foreach ( $attributes as $attribute ) {
  
  
        // skip variations
        if ( $attribute->get_variation() ) {
        continue;
        }
        $name = $attribute->get_name();
        if ( $attribute->is_taxonomy() ) {
  
            $terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
            // get the taxonomy
            $tax = $terms[0]->taxonomy;
            // get the tax object
            $tax_object = get_taxonomy($tax);
            // get tax label
            if ( isset ( $tax_object->labels->singular_name ) ) {
                $tax_label = $tax_object->labels->singular_name;
            } elseif ( isset( $tax_object->label ) ) {
                $tax_label = $tax_object->label;
                // Trim label prefix since WC 3.0
                if ( 0 === strpos( $tax_label, 'Product ' ) ) {
                   $tax_label = substr( $tax_label, 8 );
                }                
            }
  
  
            $out .= '<li class="' . esc_attr( $name ) . '">';
            $out .= '<span class="attribute-label">' . esc_html( $tax_label ) . ': </span> ';
            $out .= '<span class="attribute-value">';
            $tax_terms = array();
            foreach ( $terms as $term ) {
                $single_term = esc_html( $term->name );
                if ( $single_product ) {
                $term_link = get_term_link( $term );
                if ( ! is_wp_error( $term_link ) ) {
        $single_term = '<a href="' . esc_url( $term_link ) . '">' . esc_html( $term->name ) . '</a>';
    }
}
                array_push( $tax_terms, $single_term );
            }
            $out .= implode(', ', $tax_terms);
            $out .= '</span></li>';
 
        } else {
            $value_string = implode( ', ', $attribute->get_options() );
            $out .= '<li class="' . sanitize_title($name) . ' ' . sanitize_title( $value_string ) . '">';
            $out .= '<span class="attribute-label">' . $name . ': </span> ';
            $out .= '<span class="attribute-value">' . esc_html( $value_string ) . '</span></li>';
        }
    }
  
    $out .= '</ul>';
  
    echo $out;
}
add_action('woocommerce_single_product_summary', 'isa_woocommerce_all_pa', 25);

Is there a similar example that we can see?

What is the link to your site?

December 20, 2018 at 4:44 pm #3021674

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+01:00)

Hi,

thanks for contacting us.

Your code doesn't use the WPML API nor the strings use GetText, so this is probably why you don't see your attribute. Our support policy cannot offer support for custom code, but I suggest you read our documentation:
https://wpml.org/documentation/support/wpml-coding-api/
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference
https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/
https://wpml.org/faq/language-setup/

Let me know if this helps you or if you need further assistance.

December 20, 2018 at 4:53 pm #3021792

John

Ok. I understand what you said....i will try to look over documentations...the idea is that only the attributes doesn't show translated the variations works perfectly, and if i scroll down to additional informations then everything is perfect..i thought is something wrong to the functions above.
Thanks anyway...i was looking to get more help from wpml but whatever.

December 21, 2018 at 8:08 am #3023847

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+01:00)

Hi,

I'm not sure what you mean with "only the attributes doesn't show translated". You can set attributes as not translatable in WPML -> Settings

December 21, 2018 at 8:52 am #3023922

John

I'm referring to the function above. When I use it only variations are shown in 2nd language. The attributes are displaying on initial language.
http://wpml.org/forums/topic/show-translated-woocommerce-custom-product-attributes-with-php-functions/
The function is similar to the topic above and yet that user gets helped.. Not just some links to knowledge base.
I would like other support agent to support me. Sorry but you haven't been so helpful for me.

December 21, 2018 at 4:37 pm #3025609

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+01:00)

Hi,

the topic you are referring to is from 2014, and our support policy was different back then because we didn't have WPML Contractors (https://wpml.org/contractors/) and also we didn't have the workload we have now.
Currently, we don't provide support for custom code unless it uses our API.