• Resolved bek2bek

    (@bek2bek)


    I am using this code to export images to diffrent column. It works for images. I want to print categories and subcategories in different columns by making some improvements. I’m making a mistake somewhere but I couldn’t figure it out. Can you help me?

    add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
    
    function wp_all_export_csv_rows( $articles, $options, $export_id ) {
            if ( $export_id == '40' ) { // change to your export ID
                foreach( $articles as $key => $article ) {
                    if ( array_key_exists( 'ID', $article ) ) {
                        $i = 1;
                        $product = wc_get_product( $article['ID'] );
                              $m_category = get_terms( ['taxonomy' => 'product_cat'] );
                           if ( ! empty( $m_category ) ) {
           // use $m_category->parent to check if it's a parent category or sub-category.
           $articles[ $key ]['Category '] = $m_category->name; //category name from category object
                                     }
                        if ( ! empty( $product ) ) {
        
                            $featured_img = wp_get_attachment_url( $product->get_image_id() );
        
                            if ( ! empty( $featured_img ) ) {
                                $articles[ $key ]['Image ' . $i] = $featured_img;
                            }
        
                            $other_imgs = $product->get_gallery_image_ids();
        
                            if ( ! empty( $other_imgs ) ) {
                                foreach ( $other_imgs as $id ) {
                                    $i++;
                                    $img = wp_get_attachment_url( $id );
                                    $articles[ $key ]['Image ' . $i] = $img;
                                }
                            }
      
                                }
                            }
                        }
                    }    
    var_dump($m_category);
            return $articles; // Return the array of records to export
    	
        }
        add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
Viewing 4 replies - 1 through 4 (of 4 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter bek2bek

    (@bek2bek)

    So when use code below

    $m_category = $product->get_category_ids();
    	if ( ! empty( $m_category ) ) {
    	 foreach($m_category as $category) {
    	   $kat = get_cat_name($category); 
     }
    }

    $kat returns string(0) but $m_category returns id arrays

    • This reply was modified 4 years, 1 month ago by bek2bek.

    Hello,

    Thank you for sending your question to our forum. Kindly note that our support for custom code is really limited, I recommend debugging the code, or also you can hire someone to help you out.

    The resource pages above in the previous response mentioned by Mirko are great for looking for a workaround.

    I hope this points you in the right direction.

    Thank you.

    • This reply was modified 4 years, 1 month ago by Igor H.
    Igor H

    (@ihereira)

    We haven’t heard back from you in a while (I think you have been able to find a solution), so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Seperate Categories to Diffrent Columns’ is closed to new replies.