Support » Fixing WordPress » Problem with categories for XML feed

  • Resolved jtomcik

    (@jtomcik)


    Hello to you all,

    OK, so I’ve recently started using a XML feed generator for our WC site, and I got it working in a few hours, except one problem, that I’ve been trying to solve for a day now, but nothing seems to work.

    To my best understanding, the problem lies in the default alphabetical sorting of WC (or WP) categories. E.g. here is the screenshot of a product page in front end – http://snag.gy/8anCZ.jpg

    If you look at the ‘Kategórie:’ row, the order is alphabetical and not hierarchical, as I would wish, i.e. JUNIOR -> Chlapec (Boy) -> Teplákové súpravy (Tracksuits). It is the same on the Products page in WC Administration.

    This is what it looks like at the Categories page – http://snag.gy/73HXT.jpg – the categories include their subcategories and subsubcategories (we use 4 levels at most). And also, I tried the ‘Category Order and Taxonomy Terms Order’ plugin, which also showed categories nicely sorted without me doing anything – http://snag.gy/srpx6.jpg (alas the plugin did not resolve the issue of them displaying wrong).

    Now to the XML feed module, the code looks like this (the relevant part) :

    foreach (array_unique($products, SORT_REGULAR) as $prod) {
      $product = get_product($prod->ID);
      $producttype = get_product($prod->product_type);
      $attributes = $product->get_attributes();
      $attrname = array();
      $terms = get_the_terms( $prod->ID, 'product_cat' );
      foreach ($terms as $term) {
      $product_cat_id = $term->term_id;
      $termname = $term->object_id;
      }...
    if(count($attrname)==2 AND $product->is_type('variable' ) ){
                $i=0;
                $prodvariations = $product->get_available_variations();
    
                foreach ($prodvariations as $prodvariation) {
                    echo '	<CATEGORYTEXT><![CDATA['.get_option('barnone_sk_categorytest'.$product_cat_id).']]></CATEGORYTEXT>'.PHP_EOL;
                }

    The get_option category which is called, is defined on the settings page where all the lowest categories are manually assigned a category from the site I generate the feed for.

    One last screen, I promise – http://snag.gy/n7RWl.jpg. You can see 2 products, and when you look at the categories on the right, the correct category is only assigned to the first product, because the last shown category is also the ‘last child’, or the lowest in hierarchy.
    Thus, the second product has a wrong product_cat_id (i.e. JUNIOR) and just a blank space is shown in the feed. (this is the feed btw.: http://eshop.garlen.sk/?feed=heureka-sk)

    Does anybody have any ideas how to solve this? I apologize if I was a tad too descriptive.
    Thanks for any help.
    J.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jtomcik

    (@jtomcik)

    Oh, now I see it took me a while to write this, I got signed out automatically and posted this on the main WP Support page, not the WooCommerce Support, sorry for that.

    Thread Starter jtomcik

    (@jtomcik)

    Nevermind, I solved it by just checking the very last category that the product is in. I very naively thought WC wouldn’t show products in a category if it wasn’t checked on the product page, but now I heard it can. Didn’t want to go this way because it would take a lot of time, but it solves the issue alright.

    Thread Starter jtomcik

    (@jtomcik)

    Solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with categories for XML feed’ is closed to new replies.