Content Egg Pro Plugin
Pricing
  • Content Egg WP Plugin
  • Getting started
    • Installation
    • Upgrade Free to Pro
    • Automatic updates
  • Modules
    • General information
    • Affiliate modules
      • Aliexpress module
      • Amazon module
      • Amazon No API module
      • Avantlink Products module
      • Awin module
      • Bestbuy module
      • Bolcom module
      • CityAds Products module
      • CJ Products module
      • Daisycon module
      • Ebay module
      • Envato module
      • Flipkart module
      • GdeSlon module
      • Impactradius module
      • Kelkoo module
      • Kieskeurignl module
      • Rakuten Linkshare module
      • Linkwise module
      • Lomadee Products module
      • Offer module
      • Optimisemedia module
      • Shareasale module
      • Shopee module
      • Tradedoubler Products module
      • Tradetracker Products module
      • Trovaprezzi
      • Udemy module (deprecated)
      • Sovrn (Viglink) module
      • Walmart module
      • Webgains module
    • Coupon modules
      • Admitad Coupons module
      • CJ Links module
      • Coupon module
      • Lomadee Coupons module
      • Skimlinks Coupons module
      • Tradedoubler Coupons module
      • Tradetracker Coupons module
    • Content modules
      • Bing Images module
      • Flickr module
      • Freebase module
      • Google Books module
      • Google Images module
      • Pixabay module
      • Qwant Images module
      • Related Keywords module
      • RSS Fetcher module
      • Twitter module
      • Youtube module
    • Feed modules
      • General information
      • Field mapping
      • Mass import
      • Price comparison based on feeds
      • Troubleshooting
    • Module cloning
    • Deprecated modules
    • My network isn't listed
    • Affiliate Egg integration
    • Deeplink settings
  • Set Up Products
    • How to add products
    • Price comparison websites
    • Autoblogging
    • Fill tool
    • Products page
    • How to add badge icons
  • Frontend
    • How content is displayed
    • 🆕Gutenberg blocks
    • 👉Shortcode parameters
    • Product groups/variations
    • Product sorting
    • Featured images
    • Frontend Search
    • Translation
    • Greenshift templates
  • Updating products
    • Price update
    • Product list update
    • Why prices don't update
    • Out-of-stock products
    • Price history
    • Price alert
    • Price movers
  • 🪄AI
    • Activating AI features
    • AI content generation
    • Smart groups
    • OpenAI API
    • Claude API
    • OpenRouter API
    • Custom prompts
  • WooCommerce Integration
    • General information
    • Product synchronization
    • Attributes synchronization
    • WooCommerce and autoblogging
  • Integrations
    • Affiliate Egg Integration
    • Cashback Tracker Integration
    • External Importer integration
    • WooCommerce Integration
  • Custom Templates
    • Customizing templates with CSS
    • How to install a custom template
    • 🪄ChatGTP Template Creator
    • How to create a custom template
  • Customization
    • Localization
    • For developers
    • Useful code snippets
    • REST API
    • Compatibility with themes
  • FAQ
    • How to add price comparison blocks to WooCommerce
    • How to add custom logos for merchants
    • How to import from CSV data feeds
    • How to change the date format or the date is not being displayed
    • Is Content Egg GDPR Compliant?
    • How to add offer count as a custom field
    • How to add products programmatically
  • Troubleshooting
    • Small font size in product blocks
    • Nothing found while search
Powered by GitBook
On this page
  1. FAQ

How to add products programmatically

$post_id = 3537;
$module_id = 'Offer';

$products = [
    [
        'unique_id' => 'prod001',
        'title' => 'Wireless Headphones',
        'subtitle' => 'Crystal-clear sound with deep bass',
        'description' => 'High-quality wireless headphones with noise cancellation.',
        'img' => 'https://example.com/images/headphones.jpg',
        'url' => 'https://example.com/products/headphones',
        'orig_url' => 'https://example.com/products/headphones',
        'price' => 99.99,
        'priceOld' => 149.99,
        'currencyCode' => 'USD',
        'merchant' => 'ExampleStore',
        'badge' => 'Best Seller',
        'badge_color' => 'primary',
        'logo' => 'https://example.com/logos/examplestore.png',
        'ratingDecimal' => 4.5,
        'order' => '',
        'stock_status' => 1,
    ],
    [
        'unique_id' => 'prod002',
        'title' => 'Smart Watch',
        'subtitle' => 'Track your fitness in style',
        'description' => 'Fitness-focused smartwatch with heart rate monitor and GPS.',
        'img' => 'https://example.com/images/smartwatch.jpg',
        'url' => 'https://example.com/products/smartwatch',
        'orig_url' => 'https://example.com/products/smartwatch',
        'price' => 129.99,
        'priceOld' => 179.99,
        'currencyCode' => 'USD',
        'merchant' => 'TimeTech',
        'badge' => 'Hot Deal',
        'badge_color' => 'primary',
        'logo' => 'https://example.com/logos/timetech.png',
        'ratingDecimal' => 5,
        'order' => '',
        'stock_status' => 1,
    ],
    [
        'unique_id' => 'prod003',
        'title' => 'Bluetooth Speaker',
        'subtitle' => 'Powerful sound in your palm',
        'description' => 'Portable Bluetooth speaker with deep bass and waterproof design.',
        'img' => 'https://example.com/images/speaker.jpg',
        'url' => 'https://example.com/products/speaker',
        'orig_url' => 'https://example.com/products/speaker',
        'price' => 49.99,
        'priceOld' => 69.99,
        'currencyCode' => 'USD',
        'merchant' => 'SoundPro',
        'badge' => 'Editor\'s Pick',
        'badge_color' => 'primary',
        'logo' => 'https://example.com/logos/soundpro.png',
        'ratingDecimal' => 4.7,
        'order' => '',
        'stock_status' => 1,
    ],
];

\ContentEgg\application\components\ContentManager::saveData($products, $module_id, $post_id);
PreviousHow to add offer count as a custom fieldNextSmall font size in product blocks

Last updated 22 days ago