WooCommerce return product object by id

前端 未结 4 1577
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 18:39

I am creating a custom theme for woocommerce and I need to be able to create a mini product display. I am having problems finding documentation on the woocommerce api. I hav

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 19:01

    Another easy way is to use the WC_Product_Factory class and then call function get_product(ID)

    http://docs.woothemes.com/wc-apidocs/source-class-WC_Product_Factory.html#16-63

    sample:

    // assuming the list of product IDs is are stored in an array called IDs;
    $_pf = new WC_Product_Factory();  
    foreach ($IDs as $id) {
    
        $_product = $_pf->get_product($id);
    
        // from here $_product will be a fully functional WC Product object, 
        // you can use all functions as listed in their api
    }
    

    You can then use all the function calls as listed in their api: http://docs.woothemes.com/wc-apidocs/class-WC_Product.html

提交回复
热议问题