php - json api controller for woocommerce category images -
i seek utilize json api woocommerce data. regular wp jason api can utilize custom post type 'product' of postdata need category data, name , specially category images. figured write simple controller around funtion get_terms( 'product_cat'). bet lack of php oop knowledge fail add together key (image), value (image_url). far adding lastly image pair details json find these details each category object image value in between other key,value pairs
here controller:
<?php /* controller name: woocommerce category images controller description: woocommmerce category images controller */ final class json_api_woocatimages_controller { public function info() { homecoming array( 'version' => '1.0' ); } public function get_category_images() { $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); foreach( $product_categories $cat ) { // thumbnail id user term_id $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); // image url $image = wp_get_attachment_url( $thumbnail_id ); // here wrong..... $product_categories['image'] = $image; } homecoming array( "woocommerce categories" => $product_categories ); } }
here's result: http://funshopping.mystagingwebsite.com/api/woocatimages/get_category_images/
i utilize help on either how add together these image info each product_categories array and/or how differently standard json api methods maybe 'get_category_index'. honest have no clue utilize other category index back. it's same controller have seen on how menu index able values , id's of actual menu's beingness used. sure missing here.
the controller should be:
<?php /* controller name: woocommerce category images controller description: woocommmerce category images controller */ final class json_api_woocatimages_controller { public function info() { homecoming array( 'version' => '1.0' ); } public function get_category_images() { $args = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); foreach( $product_categories $cat ) { // thumbnail id user term_id $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); // image url $image = wp_get_attachment_url( $thumbnail_id ); $cat->{'image'}=$image; } homecoming array( "woocommerce categories" => $product_categories ); } }
php json object woocommerce category
No comments:
Post a Comment