Support » Plugin: WP Shopify » How to use PHP functions

  • Resolved JCLondon

    (@jclondon)


    Hi there,

    I’m trying to use the PHP function to retrieve a list of products by a given collection id. Therefore I have these two lines of code in my template

    $Products = WP_Shopify\Factories\DB\Products_Factory::build();
    $result = $Products->get_products_by_collection_ids(164430086192);

    where 164430086192 is the code of the collection I want to show the products of.

    When I print_r($result) I get an empty array(). If I print_r($Products) I get

    WP_Shopify\DB\Products Object ( [table_name_suffix] => wps_products [table_name] => wp_wps_products [version] => 1.0 [primary_key] => id [lookup_key] => product_id [cache_group] => wps_db_products [type] => product [default_product_id] => 0 [default_post_id] => 0 [default_title] => [default_body_html] => [default_handle] => [default_post_name] => [default_image] => [default_images] => [default_vendor] => [default_product_type] => [default_published_scope] => [default_published_at] => 2020-10-21 13:46:32 [default_updated_at] => 2020-10-21 13:46:32 [default_created_at] => 2020-10-21 13:46:32 [default_admin_graphql_api_id] => [default_metafields_global_title_tag] => [default_metafields_global_description_tag] => [metafields_global_title_tag] => [metafields_global_description_tag] => )

    Am I using that function correctly?

    Many thanks
    Jeff

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Andrew @ wpshop.io

    (@andrewmrobbins)

    @jclondon

    Make sure to pass an array to get_products_by_collection_ids(), like this:

    
    $Products->get_products_by_collection_ids([164430086192]);
    

    Just to confirm, did you sync your collections? By default these are turned off.

    You can enable this by going into your plugin settings and clicking the “General” section. Make sure both Enable Default Pages and Create Product Detail Pages? are enabled.

    Then, if you’re on the Pro version, go to the “Syncing” section and ensure Selective Sync is set to both Products and Collections.

    Then, go to the Tools tab and use the Sync Product & Collection Detail Pages button.

    Once that finishes you should see your products returned.

    Thread Starter JCLondon

    (@jclondon)

    All clear now, thanks a lot!

    • This reply was modified 5 months, 3 weeks ago by JCLondon.
    Plugin Author Andrew @ wpshop.io

    (@andrewmrobbins)

    Awesome no problem!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.