I'm trying to add a script to php/Woocommerce (theme: customify) because beyond 20 product variation, I cannot add more.
My question is : where add the script and what is the script ?
I found some informations but not the solution. I tried this one :
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'handsome_bearded_guy_increase_variations_per_page' );
function handsome_bearded_guy_increase_variations_per_page() {
return 50;
}
but no results.
Related
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
I'm new to php and Woocommerce. I know this question has already been asked but i can't figure out how to make it work ... Right now, i have 3 different categories on my Woocommerce shop ( i'm developping using Understrap ). I've created my basic product page layout, everything works fine. Now, i'd like to create a custom layout for my products that are in my "cleaning" category.
What i did for now is add this to my functions.php child theme :
add_filter('template_include', 'cleaning_single_product_template_include', 10);
function cleaning_single_product_template_include($template)
{
if (is_product() && (has_term('cleaning', 'product_cat'))) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-cleaning.php';
}
return $template;
}
Then i've created a single-product-cleaning.php file inside my woocommerce folder. For now, i've just pasted an <h1>LOREM</h1> to see if it shows up on the page, but it doesn't ..
Now in the code i've added to my functions.php, if i replace the content of my function with a simple
echo "test"; die();
It works, the "test" message appears on my cleaning product pages. But if i let the code i've written as is, then it just display the regular product page from single-product ... Any idea what i am missing here ?
EDIT : i've found this thread on stackoverflow where he seems to have found a solution (see his last comment) but i don't understand what code he moved or how he solved it ..
Finally fixed! For those having the same problem, i've just modified a little bit my functions.php function like this :
add_filter('template_include', 'cleaning_single_product_template_include', 50, 1);
function cleaning_single_product_template_include($template)
{
if (is_singular('product') && (has_term('cleaning', 'product_cat'))) {
$template = get_stylesheet_directory() . '/woocommerce/single-product-cleaning.php';
}
return $template;
}
really hoping someone can help with this as I thought it would be far more simple!
Long story short, I have created a script that populates the upsells of WooCommerce products, all works great using the API and they are there. They show on the product page as expected but in a completely different order to how they were inputted in the admin area and I cannot seem to find a way for the order to follow admin?
function filter_woocommerce_upsells_orderby( $orderby ) {
return 'menu_order';
};
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
Above is the hook I have found but from the options I have found such as menu order / id / price etc, there is not simply an overide option to ignore the order and just take them as they are in admin!?
Please help!
I also encountered this problem. And i have an idea.
I checked all wordpress parameters about Order & Orderby.Link is https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
And i use the paramteters name "none",It can make your orderby not based on any sorting rules.In other words, it is sorted according to upsells. here is the code.
// ORDER BY
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
function filter_woocommerce_upsells_orderby( $orderby ){
return "none";
};
// ORDER
add_filter( 'woocommerce_upsells_order', 'filter_woocommerce_upsells_order', 10, 1 );
function filter_woocommerce_upsells_order(){
return 'asc'; // Default is 'desc';
};
But it is still chaotic, when adding any product to upsells, it is still random. Therefore I also used a plug-in "WooCommerce Drop/Drag For Upsells Cross-Sells", which allows you to drag your products in upsell at will.
If you have any question you can ask me.
Thanks.
I'm trying to get the search term within a woocommerce page to display it dynamically on the results page so the user knows what term they searched on.
ex. "Showing results for $searchTerm"
Is there a way to get the search term from the page that was used?
You can make use of the get_search_query() and is_search() functions like this:
add_action( 'woocommerce_before_main_content', 'show_search_query_on_page', 1 );
function show_search_query_on_page() {
if(is_search()) {
echo '<h2>Showing results for: '.get_search_query().'</h2>';
}
}
I got this working through shortcodes by editing the functions.php file to include:
add_shortcode('searchterm', 'get_searchterm');
function get_searchterm() {
return $_GET['ixwpss'];
}
Then I could use [searchterm] as a shortcode on the page. Unfortunately I had to "touch" the php file.
I'm using WooCommerce plugin for Wordpress. It comes with a widget called WooCommerce Product Categories which can display a drop-down of all your product categories. I have searched online and found the following code which will exclude certain categories from appearing, categories with ID 16 and 20 in this snippet:
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['exclude'] = array('16','20');
return $cat_args;
}
What I need is the opposite. I want a filter/function similar to above, but which enables me to specify which categories to include - i.e. exclude everything but the IDs that I specify.
You can try this;
add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
function woo_product_cat_widget_args( $cat_args ) {
$cat_args['include'] = array('16','20');
return $cat_args;
}
actually you can use any of these arguments that listed on this page https://codex.wordpress.org/Template_Tags/wp_list_categories
Hope that helps!