Home › Forums › Add-ons › Repeater Field › Copy/Paste Repeater Field Array
I have 2 CPT’s: one “lc_template”, the other “lc_registration”
I have an ACF repeater field assigned to both “lc_photos_list”
The repeater field contains the subfields “lc_photograph” and “lc_photograph_label”
Upon a successful woocommerce purchase (hook: woocommerce_payment_complete_order_status_completed), I wish to COPY the contents of the “lc_photos_list” that is in an “lc_template” CPT to a “lc_registration” CPT.
add_action( 'woocommerce_payment_complete_order_status_completed', 'lc_complete_for_status' );
function lc_complete_for_status( $order_id ){
$copyPhotosObject = get_field("lc_photos_list", 579 );
update_field("lc_photos_list", $copyPhotosObject, 576);
}
This was my attempt but nothing seems to be happening… and my questions is before I spend way too long trying to figure out why…. is this the correct approach? Thanks in advance..
Can you provide more info?
How is the data being added to the contents being added to lc_photos_list in the first instance?
If you then add info to lc_registration, does it matter what the post ID will be?
Based on your code, something like:
add_action( 'woocommerce_payment_complete_order_status_completed', 'lc_complete_for_status' );
function lc_complete_for_status( $order_id ){
if( have_rows('lc_photos_list', 579) ):
while( have_rows('lc_photos_list', 579) ) : the_row();
$sub_value = get_sub_field('sub_field');
$post_id = 576;
$row = array(
'field_61645b916cbd7' => $sub_value #this is your repeater field key
);
$i = add_row('field_61645b866cbd6', $row, $post_id); #this is the key for the main repeater
endwhile;
endif;
#update_field("lc_photos_list", $copyPhotosObject, 576);
}
I don’t know the repeater field info or how you get the post IDs (579/576)
Should hopefully get you underway.
Code is untested!
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.