• Resolved jakariaahmed118477

    (@jakariaahmed118477)


    function skyverge_change_attribute_list_display( $output, $attributes, $values ) {
    
    return wpautop( wptexturize( implode( ‘<br />’, $values ) ) );
    }
    add_filter( ‘woocommerce_attribute’, ‘skyverge_change_attribute_list_display’, 10, 3 );

    I was applied this code for replace the comma(,) to line break between two terms in attribute. But the problem is it applied to my all attributes. I want to apply it on some specific attributes. How i can do it? Help me……

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    To only apply it on certain attributes, you would need to do a comparison to check the attribute — something like the snippet below might work. You will need to replace the names (i.e. pa_size, pa_color) with the names of your attributes:

    
    function skyverge_change_attribute_list_display( $output, $attributes, $values ) {
        $att_string = "";
    
        if( $attributes["name"] == "pa_size" || $attributes["name"] == "pa_color" ) {
            $att_string = wpautop( wptexturize( implode( '<br />', $values ) ) );
        } else {
            $att_string = $output;
        }
    
        return $att_string;
    }
    add_filter( 'woocommerce_attribute','skyverge_change_attribute_list_display', 10, 3 );
    

    I hope that helps!

    Thread Starter jakariaahmed118477

    (@jakariaahmed118477)

    I add this code on my functions.php by replace attribute name. But it’s not working. What i can do naw? Help me….

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    To clarify, are these global product attributes (created under Products > Attribute), or custom attributes added on individual products?

    Please send the code as you have edited it with your own product names (use the CODE tag tool in the forum reply editor toolbar).

    Thank you.

    Thread Starter jakariaahmed118477

    (@jakariaahmed118477)

    I have created attributes under product > attribute. So it’s a global product attribute. I was use this code on my functions.php

    function skyverge_change_attribute_list_display( $output, $attributes, $values ) {
        $att_string = "";
    
        if( $attributes["name"] == "cpu" || $attributes["name"] == "gpu" ) {
            $att_string = wpautop( wptexturize( implode( '<br />', $values ) ) );
        } else {
            $att_string = $output;
        }
    
        return $att_string;
    }
    add_filter( 'woocommerce_attribute','skyverge_change_attribute_list_display', 10, 3 );

    I want to apply this code to ‘CPU’ and ‘GPU’ that’s why i replace it by attributes name. Thanks.

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    I see, thank you for clarifying.

    Please try using this instead (I just added the pa_ part ahead of the names of the product attributes — I’m not entirely sure of the reason, but for global attributes, I believe that is necessary):

    
    function skyverge_change_attribute_list_display( $output, $attributes, $values ) {
        $att_string = "";
    
        if( $attributes["name"] == "pa_cpu" || $attributes["name"] == "pa_gpu" ) {
            $att_string = wpautop( wptexturize( implode( '<br />', $values ) ) );
        } else {
            $att_string = $output;
        }
    
        return $att_string;
    }
    add_filter( 'woocommerce_attribute','skyverge_change_attribute_list_display', 10, 3 );
    
    Thread Starter jakariaahmed118477

    (@jakariaahmed118477)

    Thanks a lot bro

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hehe, happy to help, bro! : )

    I’m going to mark this thread as resolved. If you have any further questions, please start a new thread.

    Have a wonderful day!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocommerce attribute problem’ is closed to new replies.