Tagged: attributes, woocommerce
-
AuthorPosts
-
January 18, 2022 at 10:19 pm #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?
January 19, 2022 at 6:41 am #1336120Hey 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,
IsmaelJanuary 19, 2022 at 4:42 pm #1336231Hello, 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.
January 20, 2022 at 8:38 am #1336308Hi,
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,
IsmaelJanuary 20, 2022 at 3:22 pm #1336371That 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.
January 20, 2022 at 3:57 pm #1336376 -
AuthorPosts
- The topic ‘WooCommerce product attribute 'Custom Product Attribute' change text functions.p’ is closed to new replies.