Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1336090

    Hello,

    I’ve added a handful of Custom Product Attribute’s (CPA) to a product, and all displays as expected. The main issue is that I want to add a link to the Contact page (“COUNTRIES WE SHIP TO” attribute), which I cant do via the page builder.

    In other places, I’ve used the add_filter facility to change the text on checkout pages etc, but can’t find much on hooks for product attributes and specifically CPA’s. Can anybody help with an example?

    #1336120

    Hey Webmaster,

    Thank you for the inquiry.

    Have you tried manually creating an attribute directly in the Attributes panel? You can modify the text or the value of the attribute and probably add a link to it. But you may need to override and modify the plugins/woocommerce/templates/single-product/product-attributes.php template to allow html tags in the product attribute value.

    Best regards,
    Ismael

    #1336231

    Hello, and thanks for the prompt reply.

    I have manually created Attributes, which contain textual information regarding delivery, weight and returns, but I can’t add links into the text in the Attributes.

    Don’t really want to start editing core files when an add_filter might well work better. Just don’t know how to get access to the name of the Attributes hooks.

    Thanks again.

    #1336308

    Hi,

    In the wc_display_product_attributes function, there is a filter called woocommerce_display_product_attributes, which you might be able to use to adjust the value of the product attributes but it might still not work because html tags are not allowed by default in the plugins/woocommerce/templates/single-product/product-attributes.php file.

    Example:

    add_filter("woocommerce_display_product_attributes", function($attributes, $product) {
        foreach($attributes as $attr) {
            // do something here
        }
        return $attributes;
    }, 10, 1);
    

    Best regards,
    Ismael

    #1336371

    That was such a good pointer, many thanks.

    In the end, I added each of the PCA’s programmatically with the code below, code in functions.php, just in case anybody else requires the same functionality:

    add_filter( 'woocommerce_display_product_attributes', 'custom_product_additional_information', 10, 2 );
    function custom_product_additional_information( $product_attributes, $product ) {
        // First row
        $product_attributes[ 'attribute_' . 'custom-one' ] = array(
            'label' => __('Label One'),
            'value' => __('Value 1'),
        );
    
        // Second row
        $product_attributes[ 'attribute_' . 'custom-two' ] = array(
            'label' => __('Label Two'),
            'value' => __('Value 2'),
        );
    
        return $product_attributes;
    }

    Please close this ticket, and great support once again.

    #1336376

    Hi,

    We are happy that Ismael could help and thanks for sharing your solution!

    Let us know if you have any other questions and enjoy the rest of your day :)

    Best regards,
    Yigit

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘WooCommerce product attribute 'Custom Product Attribute' change text functions.p’ is closed to new replies.