Best answer

How to use serialized data co Create Coupon in WooCommerce?

  • 16 June 2021
  • 1 reply
  • 81 views

Hello guys,

I have a Zap that creates a Coupon in a WooCommerce website.

I need a custom meta data, and luckily Zapier allows that.

The problem is the format of the data.

The field is serialized, so when I add the entry I need:

a:1:{i:0;a:4:{s:10:"product_id";s:4:"2087";s:8:"quantity";s:1:"1";s:15:"discount_amount";s:3:"100";s:13:"discount_type";s:7:"percent";}}

 

It turns into this in the database:

s:136:"a:1:{i:0;a:4:{s:10:"product_id";s:4:"2087";s:8:"quantity";s:1:"1";s:15:"discount_amount";s:3:"100";s:13:"discount_type";s:7:"percent";}}";

 

It's considered a string and serialized again.

 

I can't find the right format to use, anyone can help with that?

 

 

Thanks

Daniele

icon

Best answer by MarinaH 17 June 2021, 22:54

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 4
Badge +9

Hi @wp-ok!

Thanks for the question 👍

Zapier’s Formatter allows for the conversion of Line Item fields to individual fields: https://zapier.com/help/create/format/convert-line-items-into-text-strings

However, that may not help out here and you may need a Code step. The best place to ask for help with your code is http://stackoverflow.com. Just tag your question with a “Zapier” tag and usually there will be folks who are willing to help you out. You can see all the questions that have already been asked here: https://stackoverflow.com/questions/tagged/zapier

Alternatively, where is the data coming from, which app, do you have the option to change the formatting of the data in the trigger app, to get it into a format you can use in the Create Coupon action in WooCommerce?