How do I add product attributes to the product page in WooCommerce? - wordpress

I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?
It seems like an obvious thing but I haven't found options or snippets for it.

First you add attributes to product. Then you use this snippet in functions.php:
// maybe remove tab with attributes
add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
function remove_info( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// show attributes
add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
function summary_attributes() {
global $product;
if ( $product->has_attributes() ) {
wc_display_product_attributes( $product );
}
}

Setting Up WooCommerce Attributes
go to Products > Attributes
Add the attribute name
Slug will automatically be created, and we can leave the rest of these options untouched.
Click “Add attribute” button and your attribute will be added.
Configure The Attributes
After creating attribute, now we can add different variation on your product. Click on the Configure Terms option.
Enter the variation
Add some short description
Click on the add new tab
To understand it in a better way you can follow this tutorial

Related

Remove description meta box from custom taxonomy

I'm trying to remove these areas from one of my custom taxonomies.
I've built them using the two plugins: Custom Post Types UI (to add them) and Advanced Custom Fields (to add fields to the taxonomy).
I can't see anything in the plugin settings to remove these things, but I'm not sure if I'm missing something.
I'm assuming I might need to add a function to the functions.php file. I've seen that hiding things using jQuery is a possibility, but I hear that this might show it initially on load and then hide it, so id like to learn how to doit properly.
I managed to get there with the link above and help from another website.
This function removed the two instances of the 'description' box:
function hide_description_row() {
echo "<style> .term-description-wrap { display:none; } </style>";
}
add_action( "measure_sectors_edit_form", 'hide_description_row');
add_action( "measure_sectors_add_form", 'hide_description_row');
and this one removed the column from the right hand side:
add_filter('manage_edit-measure_sectors_columns', function ( $columns ) {
if( isset( $columns['description'] ) )
unset( $columns['description'] );
return $columns;
});
To use with other taxonomies, just replace 'measure_sectors' with your own taxonomy slug

How to hide some Custom Fields from Woocommerce Admin order page

When logged in as an admin and looking at an Order in Woocommerce, there's a section with all the Custom Fields. Out of the whole list I only want it to display two of them. How do I hide the rest from this view? I don't want to delete them, but just hide from this view.
For every custom field you want hidden, add the following 4 lines of code to functions.php or using Snippets plugin:
add_filter('is_protected_meta', 'my_is_protected_meta_filter1', 10, 2);
function my_is_protected_meta_filter1($protected, $meta_key) {
return $meta_key == 'automatewoo_cart_id' ? true : $protected;
}
If you want to hide more than one, add the lines above again and change 'my_is_protected_meta_filter1' to 'my_is_protected_meta_filter2', etc
if you’re using ACF pro, there is a hook you can use to remove the field on the back end, but it’s not something that’s documented..
You could use a hook to remove specific field if is_admin() returns true.
You may need to play with this a bit to get it to work, the ACF hook is
acf/get_fields
So, for example:
add_filter('acf/get_fields', 'your_function_name', 20, 2);
function your_function_name($fields, $parent) {
// remove the fields you don't want
return $fields;
}
$fields can be a nested array of fields => sub_fields.
You need to set the priority > 10 to run after the internal ACF filter
For orders in Woocommerce the post type is 'shop_order', so your code should be:
add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
remove_meta_box( 'postcustom', 'shop_order', 'normal' );
}

How can i add a custom link field under the add to cart button?

I would like to add a custom link under add to cart for each product and I'm not sure how to do this. Each of my products has a PDF file and i would like to have the option available when i edit products so I can add the link to them. I don't want to ad it in the description just under the add to cart button.
You can use the woocommerce_after_add_to_cart_button hook to place content below the add to cart button:
function add_content_below_cart_button( ) {
// do something to add your link
};
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_below_cart_button', 10, 0 );

woocommerce product attributes dropdown not appear

i can't select product color or size before add product to cart .
all attributes showing like text not selection
i need to show product attributes dropdown list (options)
i try :
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
enter image description here
Once you’ve created attributes you’ll need to use those to create variations on your product. I assume what you’re saying is that you click on an attribute and it then takes you to a page showing you any product that is using that attribute.
once your attributes are added to the product follow the rest of this doc to get variations created. Then you’ll have drop down options for those variations on your product.

Woocommerce choose grid or list view for each category

I want the possibility to choose between grid and list view for each Woocommerce category. I have found this plugin: https://nl.wordpress.org/plugins/woocommerce-grid-list-toggle/
However, the plugin is meant for the shopper to choose whether to display items in grid view or list view. What I truly want is the ability to assign a view for each category in the back-end.
Example:
Category A is displayed as grid
Category B is displayed as list
Breaking my head over this.
Similar to this question you need to filter template_include. You need to call your custom archive template archive-list-view.php and save it in your theme's woocommerce folder. Obviously, you can name it anything you like, you will just have to adjust the code below to match.
Folder structure:
/theme-folder/functions.php
/theme-folder/woocommerce/archive-list-view.php
On the template_include filter we will check if we are on the term archive for the nussmylch product category. If so, we'll look for and supply the new template. Otherwise, the standard template is used.
EDIT: incorrect WooCommerce function is_product_taxonomy() was used. is_product_category() is needed to check for a specific category.
add_filter( 'template_include', 'so_33615903_custom_category_template', 20 );
function so_33615903_custom_category_template( $template ) {
// check you are on the taxonomy archive for specific category
if ( is_product_category( 'nussmylch' ) ) {
$new_template = locate_template( array( 'woocommerce/archive-list-view.php' ) );
if ( '' != $new_template ) {
$template = $new_template ;
}
}
return $template;
}
Working Example

Resources