Home › Forums › Add-ons › Repeater Field › Help with repeat function by order quantity and order type (memberships)
Hello! Thanks to you I have achieved good things, but I am stagnant:
I have a website with ACF in which, I have a role called parent which buys a (PRODUCT “PLAN”), with the purchase of 1 product or plan, you can add 1 new user with the child role.
At first I could not do that if I bought 5 products of the same memebresia or example plan (basic plan * 5) it would allow me to create 5 new users but this has already been solved, with some problems but that’s it.
Now I need to make it work but I can’t do it, it is that if someone buys:
plan 1
plan 2
plan 3, that is, several plans at once, this generates the permissions to add a new user for each plan or for the amount of each plan.
this is my role
add_action (‘woocommerce_order_status_completed’, ‘c7_order_completed’);
function c7_order_completed ($ order_id) {
$ order = wc_get_order ($ order_id);
$ user_id = $ order-> get_customer_id ();
$ plans = get_user_meta ($ user_id, ‘plans’, true);
if (empty ($ plans)) $ plans = 0;
foreach ($ order-> get_items () as $ item_id => $ item) {
$ product_id = $ item [‘product_id’]; // product id
$ product_qty = $ item [‘qty’]; // product quantity
$ product_id = $ item-> get_product ();
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ order ‘, $ order_id);
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ order ‘,’ field_615a9e10ec6b6 ‘);
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ plan ‘, $ product_id-> get_id ());
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ plan ‘,’ field_615a9b29093b2 ‘);
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ child ‘, 0);
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ child ‘,’ field_615a9c1f093b3 ‘);
wp_insert_post ([‘post_title’ => ‘test’. $ order_id. ‘-‘. $ product_id-> get_id ()]);
}
update_user_meta ($ user_id, ‘plans’, ($ plans + (1 * $ product_qty)));
update_user_meta ($ user_id, ‘_planes’, ‘field_615a9a13a26bf’);
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.