Woocommerce Attributes Link - wordpress

i would to modify the single product page in my shop site.
I have to remove links from attribute list in the Additional Information Tab.
I found this html is called in this page: /woocommerce/templates/single-product/product-attributes.php
In this part of code:
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
Do you know if exist another argument instead “value” for example “slug” or “name”?
If not, how can modify the call to show only value without link?
Thank’s

Add the follows code snippet in your active theme's functions.php -
function filter_woocommerce_attribute_value( $value ) {
return preg_replace( '#<a.*?>([^>]*)</a>#i', '$1', $value );
}
add_filter( 'woocommerce_attribute', 'filter_woocommerce_attribute_value', 99 );

Related

WooCommerce One Page Checkout - Hide Product Attribute Colon

I'm currently using WooCommerce OnePage CheckOut
I'd like to remove the "attribute :" text from the product list.
I copied product-list.php
FROM: "/wp-content/plugins/woocommerce-one-page-checkout/templates/checkout/"
TO: "/public_html/wp-content/themes/my-theme-child/woocommerce/checkout/product-list.php"
Modified the "/public_html/wp-content/themes/my-theme-child/woocommerce/checkout/product-list.php" file
FROM:
<span class="attributes"><?php echo esc_html( apply_filters( 'woocommerce_attribute', $attribute_string, $product->get_variation_attributes(), $product ) ); ?></span>
TO:
<span class="attributes"><?php echo esc_html( apply_filters( 'woocommerce_attribute', str_replace ("attribute: ","",$attribute_string), $product->get_variation_attributes(), $product ) ); ?></span>
Once I saved the file, seems the changes not reflected on the page?
Did I miss anything here?
Thanks
It turns out to be caching issue sigh
All good now
Another option is to update /wp-content/themes/my-theme-child/functions.php
add_filter( 'woocommerce_attribute_label', 'remove_attribute_label');
function remove_attribute_label() {
return "";
}
But with this option, the colon still exists...

Remove product dimensions from single product pages in Woocommerce

Anyone knows how to hide the product dimensions from the additional tabs on Single Product page but still show the Weight value?
I search and see this filter but it hides both weight and dimensions.
add_filter( 'woocommerce_product_get_dimensions', '__return_false' );
To hide only dimensions (but not weight), there is 2 ways to make it work.
1) using hooks (here composite filter hooks):
Looking at the template that displays dimension in single products, you can see this line:
<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>
Then if you look at WC_Product has_dimensions() method, you will see this line (where $this is the WC_Product Object instance):
return ( $this->get_length() || $this->get_height() || $this->get_width() ) && ! $this->get_virtual();
So when the length, the height and the with are empty (or false), the method returns false…
The following code that use composite hooks, will hide dimensions from "Additional information" tab in single product pages only:
add_filter( 'woocommerce_product_get_width', 'hide_single_product_dimentions', 25, 2 );
add_filter( 'woocommerce_product_get_height', 'hide_single_product_dimentions', 25, 2 );
add_filter( 'woocommerce_product_get_length', 'hide_single_product_dimentions', 25, 2 );
function hide_single_product_dimentions( $value, $product ){
// Only on single product pages
if( is_product() )
$value = '';
return $value;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To hide weight (just for info) use this composite hook code:
add_filter( 'woocommerce_product_get_weight', 'hide_single_product_weight', 25, 2 );
function hide_single_product_weight( $value, $product ){
// Only on single product pages
if( is_product() )
$value = '';
return $value;
}
2) Overriding Woocommerce templates via your active theme:
First read: Overriding Woocommerce template via the theme.
It explain how to copy the template to your theme before editing it.
Here the related template is single-product/product-attributes.php.
You will have to remove this block from the template code (from line 33 to line 38):
<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>
<tr>
<th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
<td class="product_dimensions"><?php echo esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ); ?></td>
</tr>
<?php endif; ?>
You can also use the css property display:none if everything else fails.

How to make an input allows html tags in wordpress website

I have a wordpress website and used plugin called 'WooCommerce Product Subtitle' to add text under the title.
But the input didn't allow html tags.
How can I make that input allow html tags?
TO make input allow html tags, I have done with one line of code in plugin file.
see this screenshot: https://www.screencast.com/t/AUGvfS8lyRg
Path : wp-content\plugins\wc-product-subtitle\includes\class-admin-handler.php
Line No : 58
****just replace below line with line no 58:****
Before
update_post_meta( $post_id, WCPS_DB.'subtitle', wp_kses( $_POST['product_subtitle'],array() ) );
After
update_post_meta( $post_id, WCPS_DB.'subtitle', wp_kses_post( $_POST['product_subtitle'],array() ) );
Hop this works for you.
Updated code:
Edit single product template and display the field's value
<?php
global $post;
$subtitle = get_post_meta( $post->ID, 'wc_ps_subtitle', true );
echo '<div style="font-size:26px;">'.$subtitle.'</div>';
?>
You can get subtitle from above code and manage HTML tag also.
Hop this works for you.

Open WooCommerce External Products in New Tab

I'm trying to customize WooCommerce external product links to open in new tabs...
This is my try:
added a filter to the WordPress theme functions.php file as the following:
add_filter( 'woocommerce_product_add_to_cart_url', 'woocommerce_externalProducts_openInNewTab' );
function woocommerce_externalProducts_openInNewTab($product_url) {
global $product;
if ( $product->is_type('external') ) {
$product_url = $product->get_product_url() . '"target="_blank""';
}
return $product_url;
}
What did I missed?
what you're currently doing is wrong... get_product_url is named as what it do. It will give you the url... not the html anchor that has the url, but just the url.. so you're just adding some text to the url.. that's what you are doing...
One solution is given by #Ash Patel. You can change the markup by using templates... just navigate to your plugin folder and look for this file.. woocommerce\templates\single-product\add-to-cart\external.php. You can find instructions inside it.
Now, sometimes, we don't like editing templates... especially if it's just minor edits like this...
Below code will do it the way you want it... just paste this code in your theme's functions.php.
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
add_action( 'woocommerce_external_add_to_cart', 'rei_external_add_to_cart', 30 );
function rei_external_add_to_cart(){
global $product;
if ( ! $product->add_to_cart_url() ) {
return;
}
$product_url = $product->add_to_cart_url();
$button_text = $product->single_add_to_cart_text();
do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<p class="cart">
<?php echo esc_html( $button_text ); ?>
</p>
<?php do_action( 'woocommerce_after_add_to_cart_button' );
}
Here is how you add target="_blank" to the links on archive pages:
function ns_open_in_new_tab($args, $product)
{
if( $product->is_type('external') ) {
// Inject target="_blank" into the attributes array
$args['attributes']['target'] = '_blank';
}
return $args;
}
add_filter( 'woocommerce_loop_add_to_cart_args', 'ns_open_in_new_tab', 10, 2 );
Replace ns_ part with your own namespace abbreviation.
Remove above funtion from function.php:
Use plugin files from Template folder by Template Overwrite method and then
follow below path:
woocommerce\templates\single-product\add-to-cart\external.php
open external.php where there is a tag, apply target="_blank".
it will work.

can't get apply_filter to work in wordpress thematic

I am learninig to create templates in wordpress using the thematic framework
In the header file I find:
// Filter provided for altering output of the header opening element
echo ( apply_filters( 'thematic_open_header', '<div id="header">' ) );
// Action hook creating the theme header
thematic_header();
echo ( apply_filters( 'thematic_close_header', '</div><!-- #header-->' ) );
I want to add a wrapper div element around the div id="header".../div created above
I have tried to edit the apply_filter lines like this:
echo ( apply_filters( 'thematic_open_header', '<div id="headerWrapper"><div id="header">' ) );
but it doesn't work, just printout out div id="header"
How can I get it to create the html that I want it to?
Thanks
Filters are used in functions.php or in a plugin like this:
add_filter( 'thematic_open_header', function(){
return '<div id="headerWrapper"><div id="header">';
});
The basic difference between apply_filters and do_action is that the first filters some value and returns something, while add_action will be used to do anything you want with the parameters sent or output something to the browser.
Some articles of interest: [1], [2], [3] and [4].

Resources