I want to remove just word Category: from the header on every product category page, like is shown on image below:
So that it will only show the category name, and nothing more. I know how to remove entire block, but haven't found out how to remove just that word. I found the solution below, but it doesn't do anything:
add_filter('woocommerce_show_page_title', function() {
return false;
});
You can filter out the "Category:" prefix by using the get_the_archive_title hook like this:
add_filter( 'get_the_archive_title', 'so_remove_category_prefix' );
function so_remove_category_prefix( $title ) {
$title = single_term_title( '', false );
return $title;
}
However, that will remove it for all terms (not just product categories, but blog categories, tags etc).
To specifically target product categories, you can use the is_product_category() function that is provided by WooCommerce:
add_filter( 'get_the_archive_title', 'so_remove_category_prefix' );
function so_remove_category_prefix( $title ) {
if ( is_product_category() ) {
$title = single_term_title( '', false );
}
return $title;
}
Related
I used snippet for adding prefix before price. It is working nice, but I would like to have it showed only on category product page.
I would like to hide prefix on simple product page.
Can you help me?
Thanks!
Used snippet:
add_filter( ‘woocommerce_get_price_html’, ‘njengah_text_before_price’ );
function njengah_text_before_price($price){
global $post;
$product_id = $post->ID;
$product_array = array( 25338 );//add in the product IDs to add text after price
if ( in_array( $product_id, $product_array )) {
$text_to_add_before_price = ‘ Cena od ‘; //change text in bracket to your preferred text
return $text_to_add_before_price . $price ;
}else{
return $price;
}
}
I have problem with my woocommerce downloads section on WooCommerce "my account" > "Downloads": On product variations name, there is a <span> html tag that are visible:
I have tried to remove those "span" tags using:
add_filter( 'woocommerce_customer_available_downloads', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name']);
}
but it removes all downloads altogether.
And I have also tried to remove those "span" tags using:
add_filter( 'woocommerce_available_download_link', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name'] );
}
What is my mistake and how can I get rid of these tags?
The hook woocommerce_available_download_link is included in myaccount/my-downloads.php deprecated template since WooCommerce version 2.6 (the right template file that is used is myaccount/downloads.php).
Now as downloads are loaded through WC_Customer method get_downloadable_products(), you can to use woocommerce_customer_get_downloadable_products filter hook included in this method. Or also woocommerce_customer_available_downloads filter hook too.
To remove tags from product name, you can use str_replace() or much better and efficient strip_tags():
1). First way - Using strip_tags() function:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = strip_tags( $download['product_name'] );
}
return $downloads;
}
2). Another way - Using str_replace() function:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = str_replace( array('<span>', '</span>'), array('', ''), $download['product_name'] );
}
return $downloads;
}
Code goes in functions.php file of your active child theme (or active theme). Any way should work.
If you want that to work also everywhere ("order view", "Order received", emails notifications), remove:
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
I have a wordpress website with customs posts and metas boxes.
One of these manage some pictures and I want to force the title of the post.
It should be the same as the name of the media uploaded.
Is it possible ? And how ?
Thank's
Manipulate the post title with a filter.
function change_post_title( $title, $id = null ) {
if ( is_single() ) {
$title = 'new title';
}
return $title;
}
add_filter( 'the_title', 'change_post_title', 10, 2 );
Thanks all for your help.
I have used a filter but this one :
function modify_post_title($data){
if($data['post_type'] == 'fcfm_photos' && isset($_POST['image'])) {
$data['post_title'] = substr($_POST['image'], -(strpos(strrev($_POST['image']),'/')));
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 );
And when I save the post, the post title change automatically. This is what i want.
I would like to know how to remove the word "archives" from a category or tag page title of a WordPress theme? Thank you!
Look at the official docs of get_the_archive_title(). You can modify the content through filter like below.
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
});
I have a WooCommerce store and I don't want to display the SKU on any single product page. Looking at their code, I found this filter:
/**
* Returns whether or not SKUS are enabled.
* #return bool
*/
function wc_product_sku_enabled() {
return apply_filters( 'wc_product_sku_enabled', true );
}
and I attempted to override it with this line of code I placed in a custom plugin:
apply_filters( 'wc_product_sku_enabled', false );
I also tried placing the apply_filter inside an action function for woocommerce_product_meta_start which fires right before but it still renders the SKU on the product page. Any ideas?
I think you shoul try with this:
add_filter( 'wc_product_sku_enabled', '__return_false' );
That will remove sku from all woo, back and front end. You can always hide it just by CSS if need it on admin.
The easiest way is with CSS:
.sku_wrapper {
display:none;
}
A more robust approach is to recreate the woocommerce template woocommerce/templates/single-product/meta.php in your own theme and simply comment out the line:
<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
To recreate a woocommerce template in your own theme, see:
http://docs.woothemes.com/document/template-structure/
Hiding the SKU/UGS by using cSS is not an efficient solution because it will be still part of the HTML code.
In order to hide it from the product single page and keep it in the admin page, you have to add this code in the child (or parent if you don’t have the child) functions.php :
// Remove the Product SKU from Product Single Page
add_filter( 'wc_product_sku_enabled', 'woocustomizer_remove_product_sku' );
function woocustomizer_remove_product_sku( $sku ) {
// Remove only if NOT admin and is product single page
if ( ! is_admin() && is_product() ) {
return false;
}
return $sku;
}
Make sure also in the product php page (it can have a different name depending on the theme you use) to have this condition to show the SKU in the product single page:
if (wc_product_sku_enabled() && $product->get_sku()) { // HTML code that shows the SKU in the product single page}
Make Sure to remove it from the frontend only by using this code on function.php usually you can edit the function file on theme editor
add_filter( 'wc_product_sku_enabled', 'my_remove_sku', 10 );
function my_remove_sku( $return, $product ) {
if ( !is_admin() && is_product() ) {
return false;
} else {
return true;
}
}
If you don’t need to use SKUs at all in your shop, you can disable them completely by using this plugin. simply install this plugin. https://wordpress.org/plugins/woocommerce-remove-sku/