Moving Product Meta to Additional Information Tab - php

I need to move the Product Meta content from under the "Add to Cart" button to the "Additional Information" Tab, I want it to display similar to the attribute as the client wants to move this information to Additional Information Tab.
For eg - http://yellowbee.online/product/yellow-bee-aqua-bug-led-clogs/
I need to move the "SKU", "Categories" and "Tags" to the tab which says "Additional Information"
Website is made using xStore Theme on Wordpress & Woocommerce, I have tried reading a lot on how to achieve this but all attempts have failed.
I have tried adding the following code to the functions.php in the child theme. No Luck.
function additional_product_tabs_metabox()
{
add_meta_box(
'add_product_metabox_additional_tabs',
__( 'Additional product Tabs', 'woocommerce' ),
'additional_product_tabs_metabox_content',
'product',
'normal',
'high'
);
}
I am hoping that someone has a solution on the right code to to get this hook and then to display it in the additional information tab.

This can be done with the following:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_product_additional_information', 'woocommerce_template_single_meta', 10 );
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
This will work if the related hooks are not yet customized by the theme or a plugin.

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['delivery_information'] = array(
'title' => __( 'Additional information', 'woocommerce' ),
'priority' => 16,
'callback' => 'product_additional_info_tab'
);
return $tabs;
}
function product_additional_info_tab() {
$info = get_post_meta(get_the_ID(),
'additional_product_tabs_metabox_content', true);
echo $info;
}

Related

WooCommerce custom PHP code to change Add To Cart button text

I want to update the default 'Add To Cart' text to be more suitable for my website. I have created a child theme using Astra, installed it, and then on the Theme Editor in WordPress I added a new function to my functions.php file that should have done the trick
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Check it out', 'woocommerce' );
}
From all the examples online it should be this easy. I just read from another post that this may be deprecated now? Should this still work, anything else I can check? I want this to be the button text globally on all products but each product still shows 'Add To Cart'. I saved and then reloaded my website but do not see any changes
add_filter( 'woocommerce_product_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
function mujuonly_add_to_cart( $text, $class ) {
return __( 'Check it out', 'woocommerce' );
}
Tested OK with WC 4.9

Add custom field to "Additional Information" tab (WooCommerce)

I'm trying to use ACF to add a custom attribute to the "Additional Information" tab for the products in WooCommerce. I want the admin to be able to upload a PDF that then should be set and linked in the table found in the "Additional Information" tab.
I've found the default template for the attributes in the plugin directory for WooCommerce, more precisely woocommerce/templates/single-product/product-attributes.php. This is how the template looks. I can easily just put the the_field("pdf") there to display the custom field, but the problem I'm running into is that the Additional Information tab will only show if attributes has been added through WooCommerce.
Is there some way to add additional conditional tags for when to display the Additional Information tab? If I somehow could add if (get_field("pdf")) to that code, I think this would be solved.
Updated: In Woocommerce if any dimensions, weight or product attributes (set to be displayed on product) exist, "Additional Information" tab will be displayed…
So if the tab is hidden and you have added on single-product/product-attributes.php template a custom field get_field("pdf") to be displayed that has a value, you can force "Additional Information" tab to appear using:
add_filter( 'woocommerce_product_tabs', 'woo_customize_tabs', 100, 1 );
function woo_customize_tabs( $tabs ) {
if( ! isset($tabs['additional_information']) && null !== get_field("pdf") ){
$tabs['reviews']['priority'] = 30;
$reviews = $tabs['reviews'];
unset($tabs['reviews']);
$tabs['additional_information'] = array(
'title' => __( 'Additional information', 'woocommerce' ),
'priority' => '20',
'callback' => 'woocommerce_product_additional_information_tab',
);
$tabs['reviews'] = $reviews;
}
return $tabs;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Rename Description tab in Woocommerce single product page

I pasted this code in function.php, but it didn't rename the product page tab as it supposed to (http://www.noushasasart.com/product/harsh-bark/)
function woo_remove_product_tabs($tabs) {
unset($tabs['reviews']); // Remove the reviews tab
$tabs['description']['title'] = __('Additional Information'); // Rename the
description tab
return $tabs;
}
how can I solve this?
You have forgotten the filter hook:
add_filter( 'woocommerce_product_tabs', 'woo_customize_tabs', 100, 1 );
function woo_customize_tabs( $tabs ) {
unset($tabs['reviews']); // Remove the reviews tab
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
return $tabs;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
All code is tested on Woocommerce 3+ and works.
Update (related to your comment) | Rename product description heading (inside the tab):
To rename description heading use woocommerce_product_description_heading filter hook this way:
add_filter( 'woocommerce_product_description_heading', 'rename_product_description_heading', 10, 1 );
function rename_product_description_heading( $heading ) {
return __( 'Additional Information', 'woocommerce' );
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
All code is tested on Woocommerce 3+ and works.
Official related documentation: Editing product data tabs

Add custom content to WooCommerce product description

I'm trying to inject some text in my description ending.
Is it possible with filter?
Or do i need to do this via child theme?
Been trying to find the hook for description but can only find one for short description.
Example:
This is a description.
Just some sample text to fill the description out.
What i want is to inject "This is the last line in the description" So the hole description would look like this.
This is a description.
Just some sample text to fill the description out.
This is the last line in the description
The code i have for injecting text before short description is this:
add_filter( 'woocommerce_short_description', 'single_product_short_descriptions', 10, 1 );
function single_product_short_descriptions( $post_excerpt ){
global $product;
if ( is_single( $product->id ) )
$post_excerpt = '<div class="product-message"><p>' . __( "Article only available in the store.", "woocommerce" ) . '</p></div>' . $post_excerpt;
return $post_excerpt;
}
You can use this custom function hooked in the_content filter hook this way:
add_filter( 'the_content', 'customizing_woocommerce_description' );
function customizing_woocommerce_description( $content ) {
// Only for single product pages (woocommerce)
if ( is_product() ) {
// The custom content
$custom_content = '<p class="custom-content">' . __("This is the last line in the description", "woocommerce").'</p>';
// Inserting the custom content at the end
$content .= $custom_content;
}
return $content;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Addition - Force product description when is empty (if you want this custom text to be displayed):
add_filter( 'woocommerce_product_tabs', 'force_description_product_tabs' );
function force_description_product_tabs( $tabs ) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_product_description_tab',
);
return $tabs;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

How to remove woocommerce tab?

the products in our woocommerce shop don't need any of the default tabs so I have managed to disable them being that I only need to have the product description below the product however, while I want to keep the actual description, I believe the tab itself is redundant since there aren't any other tabs.
Basically, I want to remove the tab's & title altogether but keep the content box below it without modifying the woocommerce core php template file. Is there a way to add a filter to my WordPress theme's functions.php?
function woocommerce_default_product_tabs( $tabs = array() ) {
global $product, $post;
// Description tab - shows product content
if ( $post->post_content ) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_product_description_tab'
);
}
While CSS is great, if the stylesheet doesn't load correctly, you could end up showing someone tabs without meaning to. It is best to remove the content before loading (server side), by using a filter, as you had mentioned.
See code below as provided from Woothemes for unsetting data tabs.
EDIT Place within the functions.php file inside your theme.
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
EDIT As noted by #BasvanDijk
To remove altogether, you can use the following
add_filter( 'woocommerce_product_tabs', '__return_empty_array', 98 );
If you want to remove tabs from woo-commerce product details page, then add this code in your function.php
Option 1-
Go to functions.php and Add the following code.
(Go to Admin panel > Appearance > Editor > functions.php)
add_filter( 'woocommerce_product_tabs', 'woo_remove_tabs', 98 );
function woo_remove_tabs( $tabs ){
if(is_product()){
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
}
return $tabs;
}
By using this filter we can Remove the tabs From the Woocommerce Product Pages.
Option 2-
Or for an alternative approach just add this to your functions.php
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10);
Option 3-
Hide the tab by adding this to the bottom of woocommerce.css
.woocommerce_tabs .tabs {
display: none;
}
Read more -Woo-commerce: Remove tab from product page
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
function woocommerce_template_product_description() {
woocommerce_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_description', 40 );
This work for me with the contributions i got here. Other than removing the tab and also to place back the text.
Credits to Swapnali & Mustafa
Here is the working code:
add_filter( 'woocommerce_product_tabs', 'wcs_woo_remove_reviews_tab', 98 );
function wcs_woo_remove_reviews_tab($tabs) {
unset($tabs['reviews']);
return $tabs;
}
for some reason the code to add to functions.php file did not work for me, even tho it is in the woo commerce codex.
I was getting lots of comment spam to these products that showed reviews.
in the end I manually removed the review tab from all the products using built in wordpress/woocommerce functionality.
go to the product lising page
click the checkbox to select all products (it will only select the products on this page so you may have to go thru several pages to repeat)
from the bulk actions drop down, select edit
click apply
you will now see all the bulk edit actions you can do. Choose the "comments" drop down, and select "Do not allow"
click update
make sure to delete any cache if using a caching plugin
Excuse me but the question is not only removing tabs but also keeping the product description. If you ever tried the code above you would realize that while removing tabs you are actually removing the product description. And this is not the desired case.
You should somewhere add the following code to add it back. But unfortunately this time you can add the description side by side the picture and making a narrow column. I couldn't find the solution to add it nicely below the picture where the tabs existed before.
The code:
function woocommerce_template_product_description() {
woocommerce_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_product_description', 40 );
Using a combination of the answers above, nesting the function within the action so you can use within a conditional:
add_action( 'wp', 'custom_remove_tabs_by_tag' );
function custom_remove_tabs_by_tag() {
if ( is_product() && has_term( 'tag-term', 'product_tag' ) )
{
// Remove All Product Tabs
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
// Add Product Description
add_action( 'woocommerce_after_single_product_summary',
function () { woocommerce_get_template( 'single-product/tabs/description.php' );},
40 );
}

Categories