Support » Plugin: WooCommerce » Create programmatically a product using CRUD methods in Woocommerce 3

  • Resolved rizon

    (@rizon)


    Hi,

    I am writing a scraping plugin and I’d like to create (update and delete) a product via php code. But I get this error code:

    [25-Oct-2018 10:07:57 UTC] PHP Fatal error:  Uncaught Error: Class 'WC_Product_Simple' not found in /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-content/plugins/ff-dropship-data-scraper/ff-dropship-data-scraper.php:184
    Stack trace:
    #0 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-content/plugins/ff-dropship-data-scraper/ff-dropship-data-scraper.php(331): create_product(Array)
    #1 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-settings.php(305): include_once('/home/u1771p590...')
    #2 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-config.php(112): require_once('/home/u1771p590...')
    #3 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-load.php(37): require_once('/home/u1771p590...')
    #4 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-admin/admin.php(31): require_once('/home/u1771p590...')
    #5 /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-admin/edit.php(10): require_once('/home/u1771p590...')
    #6 {main}
      thrown in /home/u1771p590/domains/famyfuerza.com/public_html/store/wp-content/plugins/ff-dropship-data-scraper/ff-dropship-data-scraper.php on line 184

    It seems like that my plugin can’t access Woocommerce’s classes, because I have also tried to include and require them but that gives only more errors with not found classes. Woocommerce is active on my website.

    I have put my plugin in pastebin: https://pastebin.com/jDFB3qtn.

    Woocommerce system report:

    
    ### WordPress Environment ###
    
    Home URL: https://store.famyfuerza.com
    Site URL: https://store.famyfuerza.com
    WC Version: 3.4.4
    Log Directory Writable: ✔
    WP Version: 4.9.8
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: ✔
    WP Cron: ✔
    Language: en
    External object cache: –
    
    ### Server Environment ###
    
    Server Info: Apache/2
    PHP Version: 7.2.9
    PHP Post Max Size: 8 MB
    PHP Time Limit: 30
    PHP Max Input Vars: 1000
    cURL Version: 7.60.0
    OpenSSL/1.0.2k
    
    SUHOSIN Installed: –
    MySQL Version: 10.1.31-MariaDB-cll-lve
    Max Upload Size: 2 MB
    Default Timezone is UTC: ✔
    fsockopen/cURL: ✔
    SoapClient: ✔
    DOMDocument: ✔
    GZip: ✔
    Multibyte String: ✔
    Remote Post: ✔
    Remote Get: ✔
    
    ### Database ###
    
    WC Database Version: 3.4.4
    WC Database Prefix: wp_
    MaxMind GeoIP Database: ✔
    Total Database Size: 7.39MB
    Database Data Size: 5.51MB
    Database Index Size: 1.88MB
    wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.05MB
    wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB
    wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB
    wp_commentmeta: Data: 0.00MB + Index: 0.00MB
    wp_comments: Data: 0.00MB + Index: 0.00MB
    wp_dropshipapikey: Data: 0.02MB + Index: 0.00MB
    wp_links: Data: 0.00MB + Index: 0.00MB
    wp_nextend2_image_storage: Data: 0.02MB + Index: 0.02MB
    wp_nextend2_section_storage: Data: 0.02MB + Index: 0.03MB
    wp_nextend2_smartslider3_generators: Data: 0.02MB + Index: 0.00MB
    wp_nextend2_smartslider3_sliders: Data: 0.02MB + Index: 0.00MB
    wp_nextend2_smartslider3_sliders_xref: Data: 0.02MB + Index: 0.00MB
    wp_nextend2_smartslider3_slides: Data: 0.02MB + Index: 0.00MB
    wp_options: Data: 1.50MB + Index: 0.08MB
    wp_postmeta: Data: 1.91MB + Index: 0.67MB
    wp_posts: Data: 0.60MB + Index: 0.17MB
    wp_rich_web_font_family: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_cust_id: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_fields: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_id: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_info: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_mails: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_manager: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_options: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_saved: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_themes1: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_themes2: Data: 0.02MB + Index: 0.00MB
    wp_rich_web_forms_themes3: Data: 0.02MB + Index: 0.00MB
    wp_spidercatalog_id: Data: 0.00MB + Index: 0.00MB
    wp_spidercatalog_params: Data: 0.02MB + Index: 0.00MB
    wp_spidercatalog_products: Data: 0.00MB + Index: 0.00MB
    wp_spidercatalog_product_categories: Data: 0.00MB + Index: 0.00MB
    wp_spidercatalog_product_reviews: Data: 0.00MB + Index: 0.00MB
    wp_spidercatalog_product_votes: Data: 0.00MB + Index: 0.00MB
    wp_termmeta: Data: 0.02MB + Index: 0.03MB
    wp_terms: Data: 0.00MB + Index: 0.01MB
    wp_term_relationships: Data: 0.01MB + Index: 0.03MB
    wp_term_taxonomy: Data: 0.01MB + Index: 0.01MB
    wp_UPCP_Catalogues: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Catalogue_Items: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Categories: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Custom_Fields: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Fields_Meta: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Items: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Item_Images: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_SubCategories: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Tagged_Items: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Tags: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Tag_Groups: Data: 0.02MB + Index: 0.00MB
    wp_UPCP_Videos: Data: 0.02MB + Index: 0.00MB
    wp_usermeta: Data: 0.02MB + Index: 0.02MB
    wp_users: Data: 0.00MB + Index: 0.01MB
    wp_wc_download_log: Data: 0.02MB + Index: 0.03MB
    wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB
    wp_wdslayer: Data: 0.02MB + Index: 0.00MB
    wp_wdsslide: Data: 0.02MB + Index: 0.00MB
    wp_wdsslider: Data: 0.02MB + Index: 0.00MB
    wp_woof_query_cache: Data: 0.02MB + Index: 0.02MB
    wp_wplc_chat_msgs: Data: 0.02MB + Index: 0.00MB
    wp_wplc_chat_sessions: Data: 0.02MB + Index: 0.00MB
    wp_wplc_offline_messages: Data: 0.02MB + Index: 0.00MB
    wp_wplc_webhooks: Data: 0.02MB + Index: 0.00MB
    wp_wpmm_subscribers: Data: 0.02MB + Index: 0.00MB
    wp_wpsc_also_bought: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_cart_contents: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_cart_item_meta: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_checkout_forms: Data: 0.00MB + Index: 0.01MB
    wp_wpsc_claimed_stock: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_coupon_codes: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_currency_list: Data: 0.02MB + Index: 0.01MB
    wp_wpsc_download_status: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_meta: Data: 0.00MB + Index: 0.01MB
    wp_wpsc_product_rating: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_purchase_logs: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_purchase_meta: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_region_tax: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_submited_form_data: Data: 0.00MB + Index: 0.00MB
    wp_wpsc_visitors: Data: 0.00MB + Index: 0.01MB
    wp_wpsc_visitor_meta: Data: 0.00MB + Index: 0.01MB
    wp_wpsp_agent_settings: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_attachments: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_canned_reply: Data: 0.02MB + Index: 0.02MB
    wp_wpsp_catagories: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_custom_fields: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_custom_priority: Data: 0.02MB + Index: 0.02MB
    wp_wpsp_custom_status: Data: 0.02MB + Index: 0.02MB
    wp_wpsp_faq: Data: 0.02MB + Index: 0.02MB
    wp_wpsp_faq_catagories: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_panel_custom_menu: Data: 0.02MB + Index: 0.00MB
    wp_wpsp_ticket: Data: 0.02MB + Index: 0.17MB
    wp_wpsp_ticket_thread: Data: 0.02MB + Index: 0.05MB
    wp_yoast_seo_links: Data: 0.02MB + Index: 0.02MB
    wp_yoast_seo_meta: Data: 0.02MB + Index: 0.00MB
    
    ### Post Type Counts ###
    
    attachment: 439
    custom_css: 3
    flamingo_contact: 5
    flamingo_inbound: 2
    ml-slide: 6
    ml-slider: 3
    nav_menu_item: 19
    page: 19
    post: 5
    product: 33
    product_variation: 424
    revision: 187
    wpcf7_contact_form: 1
    wpsc-product: 1
    
    ### Security ###
    
    Secure connection (HTTPS): ✔
    Hide errors from visitors: ✔
    
    ### Active Plugins (21) ###
    
    Contact Form 7: by Takayuki Miyoshi – 5.0.3
    Cookie Notice: by dFactory – 1.2.44
    Custom Sidebars: by WPMU DEV – 3.1.6
    Famyfuerza Dropship Data Scraper: by Famyfuerza – 1.0.0
    Flamingo: by Takayuki Miyoshi – 1.9
    Google Analytics Dashboard for WP (GADWP): by ExactMetrics – 5.3.5
    Limit Login Attempts Reloaded: by wpchefgadget – 2.7.1
    Revision Control: by Dion Hulse – 2.3.2
    Shortcode Widget: by Gagan Deep Singh – 1.5.1
    Page Builder by SiteOrigin: by SiteOrigin – 2.8.2
    Smart Slider 3: by Nextend – 3.3.6
    SiteOrigin Widgets Bundle: by SiteOrigin – 1.12.1
    TinyMCE Advanced: by Andrew Ozz – 4.8.0
    Use Any Font: by Dinesh Karki – 4.9.2
    WooCommerce Colors: by WooThemes – 1.0.7 – Not tested with the active version of WooCommerce
    WooCommerce Product SKU Generator: by SkyVerge – 2.3.4
    WooCommerce: by Automattic – 3.4.4 – 3.5.0 is available
    Yoast SEO: by Team Yoast – 7.9.1
    WP Live Chat Support: by WP-LiveChat – 8.0.14
    WP Maintenance Mode: by Designmodo – 2.2.1
    YITH WooCommerce Ajax Product Filter: by YITHEMES – 3.5.1 – Not tested with the active version of WooCommerce
    
    ### Settings ###
    
    API Enabled: ✔
    Force SSL: ✔
    Currency: EUR (€)
    Currency Position: left
    Thousand Separator: ,
    Decimal Separator: .
    Number of Decimals: 2
    Taxonomies: Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)
    
    Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
    exclude-from-search (exclude-from-search)
    featured (featured)
    outofstock (outofstock)
    rated-1 (rated-1)
    rated-2 (rated-2)
    rated-3 (rated-3)
    rated-4 (rated-4)
    rated-5 (rated-5)
    
    ### WC Pages ###
    
    Shop base: ❌ Page not set
    Cart: #6 - /cart/
    Checkout: #7 - /checkout/
    My account: #8 - /my-account/
    Terms and conditions: ❌ Page not set
    
    ### Theme ###
    
    Name: storefront-child
    Version: 1.0.0
    Author URL: http://example.com
    Child Theme: ✔
    Parent Theme Name: Storefront
    Parent Theme Version: 2.3.3 – 2.3.5 is available
    Parent Theme Author URL: https://woocommerce.com/
    WooCommerce Support: ✔
    
    ### Templates ###
    
    Overrides: –
    
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.