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!
Thanks mate, definitely got me started.