Variant Pricing Across Products

I am looking for a way to set pricing for variants across all products. We operate a disc golf store, and different brands of discs have multiple molds, and those molds come in different plastic types. The pricing for plastic type is consistent across all of the molds.

I am looking for a way to set cost and price for each plastic type, so that if that plastic type variant is added to a new product (disc mold), it will carry over the cost and price from previous products. Is this possible?

For example, if I already have mold 111 with plastic variants aaa ($), bbb ($$), and ccc ($$$) set up, and I create a product for mold 222 and add those plastic variants, I want them to carry over their cost and pricing information.

Hi @masonkupfer ,

Thank you for reaching out about automating pricing for product variants. Based on your requirements, I’ve outlined a solution that ensures consistent pricing for your disc golf discs across all plastic types. This approach leverages Shopify’s built-in features, such as metafields, combined with automation tools like Shopify Flow.

Here’s the detailed process:

Step 1: Create Custom Metafields for Pricing

  1. Go to Settings > Custom Data > Metafields.
  2. Click Add definition and choose Product variant as the owner.
  3. Name the metafield Plastic Type Pricing.
  4. Set the content type as Single-line text and make it visible on the product details page.
  5. Save the definition.

Step 2: Add Variant Options to Products

  1. Navigate to Products > All Products and select a product.
  2. In the Variants section, click Edit.
  3. Under Option Name, enter Plastic Type and add the desired plastic types (e.g., aaa, bbb, ccc) as option values.

Step 3: Define Standard Pricing with a Metafield Template

  1. Return to Settings > Custom Data > Metafields.

  2. Create another metafield called Standard Plastic Pricing with the content type as a JSON object.

  3. Structure it as follows:

    {
      "aaa": {
        "price": "14.99",
        "cost": "7.50"
      },
      "bbb": {
        "price": "17.99",
        "cost": "9.00"
      },
      "ccc": {
        "price": "21.99",
        "cost": "11.00"
      }
    }
    

Step 4: Automate Pricing Updates with Shopify Flow

  1. Go to Settings > Apps and sales channels > Shopify Flow.
  2. Create a new workflow:
    • Trigger: Product variant created.
    • Condition: Check if the variant option name is Plastic Type.
    • Action: Update the variant price and cost using the JSON metafield values.

Additional Tips:

  • Use Shopify’s Bulk Editor for initial setup, allowing you to quickly apply plastic types and prices to existing products.
  • If you’re using inventory management apps, ensure they support metafield-based pricing structures.
  • For wholesale or promotional pricing, consider percentage-based discounts on standard prices.

This setup provides a scalable and efficient way to manage variant pricing while reducing manual effort. If you need further assistance with implementation, feel free to reach out.

Best regards,
Shubham | Untechnickle

Thank you for the help and answer. I think I have most of it figured out, except the very last step. What exactly to I need to do to create the final action step in Flow? This is as far as I got, and i’m not sure where I need to look to set that action up.

To handle the automation for updating variant pricing in Shopify, we will leverage Shopify’s Admin API and create a custom app to integrate with Shopify Flow. Below are the detailed steps:

Step 1: Create a Custom App1. Go to Settings > Apps and sales channels > Develop apps in your Shopify admin.

  1. Click “Create an app” and give it a name like “Variant Price Updater”.
  2. Configure the app:
    • Enable Admin API Access.
    • Add the following required scopes:
      • write_products
      • read_products
      • write_price_rules

Step 2: Set Up the Custom Endpoint

Create an endpoint in your custom app that Shopify Flow can call. Below is the code for the endpoint:

app.post('/update-variant-pricing', async (req, res) => {
  const session = res.locals.shopify.session;
  const { variant_id, option_value } = req.body;

  try {
    // Initialize the GraphQL client
    const client = new shopify.clients.Graphql({ session });
    
    // Query the pricing metafield
    const metafieldQuery = `{
      shop {
        metafield(namespace: "custom", key: "plastic_type_pricing") {
          value
        }
      }
    }`;
    
    const metafieldResponse = await client.query({ data: metafieldQuery });
    const pricingData = JSON.parse(metafieldResponse.body.data.shop.metafield.value);

    // Retrieve the pricing for the plastic type
    const variantPricing = pricingData[option_value];
    if (!variantPricing) throw new Error(`No pricing found for plastic type: ${option_value}`);

    // Mutation to update the variant pricing
    const mutationQuery = `
      mutation variantUpdate($input: ProductVariantInput!) {
        productVariantUpdate(input: $input) {
          productVariant {
            id
            price
            inventoryItem {
              unitCost {
                amount
              }
            }
          }
          userErrors {
            field
            message
          }
        }
      }
    `;

    const variables = {
      input: {
        id: variant_id,
        price: variantPricing.price,
        inventoryItem: { unitCost: variantPricing.cost }
      }
    };

    const response = await client.query({ data: { query: mutationQuery, variables } });

    // Handle errors in the response
    if (response.body.data.productVariantUpdate.userErrors.length > 0) {
      throw new Error(JSON.stringify(response.body.data.productVariantUpdate.userErrors));
    }

    res.status(200).send({ success: true, message: 'Variant pricing updated successfully' });

  } catch (error) {
    console.error('Error updating variant pricing:', error);
    res.status(500).send({ success: false, error: error.message });
  }
});

Step 3: Configure Shopify Flow1. In Shopify Flow, create a new workflow that triggers when a product variant is created.

  1. Add a condition to check if the option name is “Plastic Type”.
  2. Add an action to Make an HTTP Request and configure it as follows:
    • Method: POST

    • URL: Your app’s endpoint URL (e.g., https://your-app-domain.com/update-variant-pricing)

    • Headers:

      • Content-Type: application/json
      • X-Shopify-Access-Token: {{your_app_access_token}}
    • Body:

      {
        "variant_id": "{{variant.id}}",
        "option_value": "{{variant.option1}}"
      }
      

Flow Summary

The complete flow will:

  1. Trigger when a variant is created.
  2. Check if the option name is “Plastic Type”.
  3. Call the custom endpoint.
  4. Update the variant’s price and cost using the data from your metafield.

By following these steps, your custom app and Shopify Flow will automate variant pricing updates effectively.

Cheers!
Shubham | Untechnickle