<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hassan Hafeez</title>
    <description>The latest articles on DEV Community by Hassan Hafeez (@iamhassanhafeez).</description>
    <link>https://dev.to/iamhassanhafeez</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3074900%2F92a552e2-0d42-4bd5-a7d6-d3788a5a7101.gif</url>
      <title>DEV Community: Hassan Hafeez</title>
      <link>https://dev.to/iamhassanhafeez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamhassanhafeez"/>
    <language>en</language>
    <item>
      <title>Building a Custom WordPress + WooCommerce Integration with a Third-Party Wholesaler</title>
      <dc:creator>Hassan Hafeez</dc:creator>
      <pubDate>Sun, 14 Sep 2025 21:19:05 +0000</pubDate>
      <link>https://dev.to/iamhassanhafeez/building-a-custom-wordpress-woocommerce-integration-with-a-third-party-wholesaler-2og1</link>
      <guid>https://dev.to/iamhassanhafeez/building-a-custom-wordpress-woocommerce-integration-with-a-third-party-wholesaler-2og1</guid>
      <description>&lt;p&gt;One of the things I love about WordPress development is how flexible it can be when solving real-world business problems. Recently, I worked on a project for Bulk Branded&lt;br&gt;
, a UK-based supplier that needed a WooCommerce store tightly integrated with their wholesaler’s catalog.&lt;/p&gt;

&lt;p&gt;Instead of manually uploading hundreds of SKUs (and constantly updating prices/stock), I built a custom WordPress plugin that connects to the wholesaler’s API and automatically creates/updates WooCommerce products.&lt;/p&gt;

&lt;p&gt;🚩 The Challenge&lt;/p&gt;

&lt;p&gt;Fetch thousands of products from a wholesaler’s API.&lt;/p&gt;

&lt;p&gt;Keep products synced with stock, categories, and prices.&lt;/p&gt;

&lt;p&gt;Match the store’s branding and design requirements.&lt;/p&gt;

&lt;p&gt;Handle bulk imports without breaking the server.&lt;/p&gt;

&lt;p&gt;🛠️ The Approach&lt;/p&gt;

&lt;p&gt;I created a plugin that:&lt;/p&gt;

&lt;p&gt;Connects to the wholesaler API.&lt;/p&gt;

&lt;p&gt;Maps API data to WooCommerce fields.&lt;/p&gt;

&lt;p&gt;Creates categories if they don’t exist.&lt;/p&gt;

&lt;p&gt;Generates product variations (e.g., color options).&lt;/p&gt;

&lt;p&gt;Handles featured images + galleries dynamically.&lt;/p&gt;

&lt;p&gt;Runs in batches via AJAX/Cron to avoid timeouts.&lt;/p&gt;

&lt;p&gt;🧑‍💻 A Peek at the Code&lt;/p&gt;

&lt;p&gt;Here’s a simplified version of the core sync function:&lt;/p&gt;

&lt;p&gt;`//====================== Sync Products From API =================&lt;br&gt;
add_action('wp_ajax_sync_wholesaler_products', 'sync_wholesaler_products');&lt;/p&gt;

&lt;p&gt;function sync_wholesaler_products() {&lt;br&gt;
    $response = wp_remote_get('&lt;a href="https://api.xxxxxxxxxxxxxxx'" rel="noopener noreferrer"&gt;https://api.xxxxxxxxxxxxxxx'&lt;/a&gt;);&lt;br&gt;
    $products = json_decode(wp_remote_retrieve_body($response));&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (empty($products)) {
    return wp_send_json_error('No products found');
}

foreach ($products as $item) {
    // 1. Insert product
    $product_id = wp_insert_post([
        'post_type'   =&amp;gt; 'product',
        'post_title'  =&amp;gt; sanitize_text_field($item-&amp;gt;Title),
        'post_content'=&amp;gt; wp_kses_post($item-&amp;gt;Description),
        'post_status' =&amp;gt; 'publish',
    ]);

    // 2. Add SKU + Pricing
    update_post_meta($product_id, '_sku', $item-&amp;gt;SKU);
    foreach ($item-&amp;gt;Pricing as $price) {
        add_row('bulk_prices', [
            'min_quantity'  =&amp;gt; $price-&amp;gt;Quantity,
            'cost_per_unit' =&amp;gt; $price-&amp;gt;Price
        ], $product_id);
    }

    // 3. Handle Categories
    wp_set_object_terms($product_id, $item-&amp;gt;CategoryMain, 'product_cat', true);
    wp_set_object_terms($product_id, $item-&amp;gt;CategorySub, 'product_cat', true);

    // 4. Featured Image
    Generate_Featured_Image($item-&amp;gt;Images[0]-&amp;gt;SrcFull, $product_id);

    // 5. Variations (e.g., Colors)
    foreach ($item-&amp;gt;Colours as $colour) {
        $variation_id = bb_create_variation($product_id, [
            'pa_color' =&amp;gt; sanitize_title($colour-&amp;gt;Name)
        ], $colour-&amp;gt;Stock, $item-&amp;gt;Pricing[0]-&amp;gt;Price);

        Generate_Featured_Image($colour-&amp;gt;Image, $variation_id);
    }
}

return wp_send_json_success('Products synced successfully');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;👉 This is a simplified snippet — the real code includes batching, error handling, and more robust taxonomy management.&lt;/p&gt;

&lt;p&gt;📚 Lessons Learned&lt;/p&gt;

&lt;p&gt;Batch processing is everything — syncing thousands of products in one go can kill your server. Running in chunks via AJAX or WP-Cron makes it stable.&lt;/p&gt;

&lt;p&gt;Stick to WooCommerce CRUD functions — never hack the DB directly. It ensures compatibility with future updates.&lt;/p&gt;

&lt;p&gt;Dynamic taxonomies save time — programmatically creating categories/attributes on the fly keeps the store clean and organized.&lt;/p&gt;

&lt;p&gt;🎉 The Outcome&lt;/p&gt;

&lt;p&gt;The result was a fully automated WooCommerce store that:&lt;/p&gt;

&lt;p&gt;Syncs with the wholesaler daily.&lt;/p&gt;

&lt;p&gt;Creates products with variations, stock levels, and pricing.&lt;/p&gt;

&lt;p&gt;Matches the brand’s design guidelines.&lt;/p&gt;

&lt;p&gt;Saves the client hours of manual work each week.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>wordpress</category>
      <category>woocommerce</category>
      <category>plugindevelopment</category>
    </item>
  </channel>
</rss>
