Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Order tabs categories woocommerce WordPress

  • SOLVED

Hello
I have a website a guy built for me.
it's a wordpress with woocommerce integrated.
the website basically sells "relocation services"
here is a link to the website:
http://relocationshop.com/newsite

if you click on <strong>Relocation Shop</strong> you will be landed in a category page
and you will see tabs with services (woocommerce product categories)
and Choose your location drop down to choose a location.
each location has products under tabs and when clicking on one of the product you get to a product page.

inside product page you have a price that goes by a location. if you change the location the price changes.
in terms of woocommerce we have <strong>attribute</strong>: "Location" and <strong>variations</strong>: list of all the countries.

The developer that did this modified the woocommerce plugin. I know it's not good but I can live with that.
what I am trying to achieve is re-order the tabs to be permanantly different that what we have now.. Housing - Repatriation - Orientation etc etc
but the developer used a code which I can't modify

here is the product page template
https://db.tt/S6VZsXap
you will find this line there:

$query="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent=83)";

This is the order that I need:

1. Orientation
2. Immigration
3. Housing
4. Settling in
5. Starting your new life
6. Repatriation

Anyone have an idea?

Answers (2)

2014-12-23

Kyle answers:

You really don't need to be using an SQL query and can switch to get_terms like this:

$query = get_terms( 'product_cat',
array(
'parent' => '83',
'orderby' => 'slug' )
);


What you can do to manipulate the orderby is to alter the slugs in someway (you can still keep your labels) so if you changed the slugs to say '1-orientation' '2-immigration' etc. you would get your desired result. The only parameters accepted by orderby, SQL or PHP, are slug name count and ID, so you'll have to modify one of those.


hamergil comments:

Sorry I was wrong..
there are 2 queries here:
one for the select drop down and the other one for the tabs

select drop down
$query="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent=83)";

categories tabs
$query2="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent='".$country_id."')";

as you can see in the link I posted above. I really like to use your code but it won't work on one query only..
can you check?
(you can also download the file I added if you need to


Kyle comments:

It is the same thing just with the new var

$query2 = get_terms( 'product_cat',
array(
'parent' => $country_id,
'orderby' => 'slug' )
);


hamergil comments:

I am getting this error:

Warning: mysql_query() expects parameter 1 to be string, array given in /home/relocati/public_html/newsite/wp-content/themes/responsive/package-page.php on line 189

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/relocati/public_html/newsite/wp-content/themes/responsive/package-page.php on line 191

anyway you could help?


Kyle comments:

My code is replacing the SQL with PHP, so you'd have to carry that through...

So for example those rows would become

$query2 = get_terms( 'product_cat',
array(
'parent' => $country_id,
'orderby' => 'slug' )
);


$num_rows2 = count( $query2 );

And

while($pro_cat2=mysql_fetch_array($result2))

becomes

foreach ($query2 as $procat2)

Is that making sense? If you aren't comfortable with PHP Arnav's solution may be better


Kyle comments:

*Meant replacing sql/php with wp functions


hamergil comments:

For now Arnav's solution is not working too so I was thinking maybe I can get this whole code fixed
and I do prefer PHP to be honest.
let me know if you can do it and maybe require extra funds
there is a link to the file in m description
Thanks

2014-12-23

Arnav Joy answers:

try this query

$query="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent=83) orderby term_id DESC";

or

$query="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent=83) orderby term_id ASC";


hamergil comments:

Sorry I was wrong..
there are 2 queries here:
one for the select drop down and the other one for the tabs

<strong>select drop down</strong>
$query="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent=83)";

<strong>categories tabs</strong>
$query2="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent='".$country_id."')";

as you can see in the link I posted above. I really like to use your code but it won't work on one query only..
can you check?
(you can also download the file I added if you need to



Arnav Joy comments:

change this query then

$query2="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent='".$country_id."') orderby term_id DESC";

or

$query2="select * from wp_terms where term_id in(select term_id from wp_term_taxonomy where taxonomy='product_cat' and parent='".$country_id."') orderby term_id ASC";

But note that you can sort terms by id or by name or by post count .


hamergil comments:

Unfortunately I get this error:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/relocati/public_html/newsite/wp-content/themes/responsive/package-page.php on line 175

any idea?