PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

ACF - Repeater problem view on front

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

CUSTOM FILE (ACF) https://www.advancedcustomfields.com/resources/repeater/

 

I have a problem:

situation

I have an ACF repeat field, inside I have only one URL field that repeats (the idea is to have many videos for each product).

The ACF repeat field (comes out as numbers) and the URL fields (I manually put 6 of them on Bulker) have been inserted on Bulker and in itself their modification works.

The problem is in front:
I display these URLs through my own code that calls the ACF fields. on the product sheet.
-If I insert the urls from the product sheet everything is ok,
-If I insert glu url from the bulker (putting the number of videos uploaded in the repeater field), the videos are not called (as if they were not saved, but are seen by the bulker).
- If I modify even just by inserting an empty line of the Acf repeater in the woocommerce product sheet and save, everything is solved.

I would like the videos to be seen immediately, without having to save the sheet manually for each one.

Any ideas?

 

 

 

 

 

 

 

Hello

Please paste your license key here - https://share.pluginus.net/image/i20230222134241.png -> https://share.pluginus.net/image/i20230222134511.png

This is a data editing plugin and does not add third-party functionality.

It seems that this functionality uses several fields for one video and in the bulk editor only one field is updated (as it should be) but the auxiliary field for the video is not updated, which leads to an error

opz. I forgot. I recently purchased the other plugin (product filter). while this one's support has expired.

Patience was to see if a solution could be found to lighten the work.

Hello

The license key is OK

To solve this problem you need to know the data update mechanism for this custom functionality. And maybe code customization can fix this.

So, I tried to test with your function
add_filter('woobe_before_update_product_field')

 

The ACF repeater structure update is: (guide)
____________________________

// save a repeater field value
$field_key = "field_12345678";
$value = array(
    array(
        "sub_field_1"	=> "Foo",
        "sub_field_2"	=> "Bar"
    )
);
update_field( $field_key, $value, $post_id );

_______________________________

But I couldn't get it to work!
I found another post that recommended a different code:

update_sub_field( array('repeater', 1, 'sub_repeater', 2, 'sub_sub_field'), 'This value is for repeater row 1, and sub_repeater row 2!' );

With this code, even if it is not well structured to save my field (I think it updates a file that does not exist field 1 and I have field 0 because it works as an array)
In the end it works.

 

The only thing.
I have to manually update the repeater lines:
That is, my VIDEO N that has the metafield"prodott_video_boxripetitore" I have to put the number of videos that I am going to insert. but at least the inserted video appears immediately.

 

===== CODE USED  ========================================================
add_filter('woobe_before_update_product_field', function( $value, $product_id, $field_key) {

  if(  $field_key === 'prodott_video_singolo_url'
    || $field_key === 'prodott_video_boxripetitore_0_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_1_prodott_video_singolo_url' 
    || $field_key === 'prodott_video_boxripetitore_2_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_3_prodott_video_singolo_url' 
    || $field_key === 'prodott_video_boxripetitore_4_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_5_prodott_video_singolo_url' 
  ) {
        update_sub_field( array('prodott_video_boxripetitore', 1), 'This value is for repeater row 1, and sub_repeater row 2!' );
    }

//___________________
return $value;

}, 10, 3);


With the code cited above, at least the ACF file repeater is saved correctly and so the videos will be seen immediately. I just have to remember to say how many rows of the acf field repeater to have (that is, put a number in VIDEO N.)

Thanks for the food for thought.

no.. maybe it doesn't work on the online site. on the development site it seemed so.

Hello
Unfortunately, I'm not sure I understood you correctly. Did you manage to solve the problem?

On the development site this code works.
But I'm not sure on the online site. the products present do not update, but they could have a previous incorrect save.
I have to test by creating new products, but right now I'm in another phase of work.

If I solve something, I'll update you.
In the meantime, for anyone who has to manage ACF repeat this post can be useful.

Hello

Great! Thank you for your cooperation

It took me a while to refine the code. but this should work!

obviously I loaded the video fields as a normal acf repeater in a shortcode (I created the shortcode as code and called acf repeater)
I put the shortcode in a tab create new for videos in the single product card. woocomerce has some plugins for tabs (like be rocket Tab Manager).

_____________________________________________

IMPORTANT: only one arch (first empy). New videos must be inserted in numerical sequence otherwise the saving gets messed up due to the array generation.

If we have the Video1,Video2,Video3 field empty:
-insert url in Video1, wait for it to save, then insert in 2, 3 and so on.
- if instead we put url directly in video3.. the array that generates scales the empty spaces and it's a real mess.

if instead we have the Video1,Video2,Video3 full, and you only change the url there are no problems.
Essentially create the videos in numerical order and if you have to delete some videos, scale all the videos so that only the last video is deleted and therefore in the largest number

IMPORTANT 2: with this system, it is important to remove the repeater field from your BEAR custom fields, which will no longer have to be touched manually (otherwise you have to modify it as an array)
in the previous posts I had marked that I had activated it (VIDEO.N), because the number of registered urls came out as a number only.

_____________________________________________

Question:

where does this field come from?: prodott_video_boxripetitore_0_prodott_video_singolo_url.
I looked at how the ="name" of the original ACF file was recorded and I discovered that the url field that I created inside the repeater is saved in this way. each value of the repeater puts a different number.

how is the repeater composed:
very simple:
Repeater field -> prodott_video_boxripetitore
under repeater fields (only 1) -> prodott_video_singolo_url
how is the value to be saved in the repeater field? the array structure?
as you can see, if you save this simple array with internal array in the value of our repeater field, everything appears correctly
$value_repeat = array(
   array("prodott_video_singolo_url" =>"url_1"),
  array("prodott_video_singolo_url" =>"url_2"),
  array("prodott_video_singolo_url" =>"url_3"),
);
 update_field( 'prodott_video_boxripetitore',$value_repeat, $product_id );

 

HOW DO I SEE WHAT IS SAVED IN THE VARIABLE?
use a var_dump, like the example below. you can put one before to see how your file repeater is saved at the beginning and one after updating the repeater.
When saving on BEAR, this will reload both the var_dump data and the video url into the field.
BUT DON'T WORRY, you only see the VAR_DUMP DATA once as if they were printed, the saved value is only the video. reloading BEAR you find everything normal.

var_dump('_ Ripetitore Get prima_'.'<pre>',   get_field($RIPETITORE_nome,  $product_id),'</pre>'.'<br>----------------<br>');

 

 

============================================================================
===================FUNCTION ==============================================

add_filter('woobe_before_update_product_field', function( $value, $product_id, $field_key) {

  // ONLY EDIT FIELD - We activate the function only for our ACF fields and not other fields that we find in BEAR
  if(    $field_key === 'prodott_video_boxripetitore_0_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_1_prodott_video_singolo_url' 
      || $field_key === 'prodott_video_boxripetitore_2_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_3_prodott_video_singolo_url' 
      || $field_key === 'prodott_video_boxripetitore_4_prodott_video_singolo_url' || $field_key === 'prodott_video_boxripetitore_5_prodott_video_singolo_url' 
  ) {


//FILED ACF: -------------------
$RIPETITORE_nome               = 'prodott_video_boxripetitore';         //Repeater field
$ELEMENTO_SOTTO_RIPETIORE_nome = 'prodott_video_singolo_url';           //single field on Repeater




//--GET NUMBER FROM FIELD to edit -----------
//from the field that we modify in BEAR we get the number of the field type from 'prodott_video_boxripetitore_2_prodott_video_singolo_url' we get 2 //ATTENTION that on the bulker this value is VIDEO 3

$string_array_repeatfield = $field_key; //field of BEAR that you edit

// Using preg_match_all to extract numbers 
preg_match_all('/\d+/', $string_array_repeatfield,  $string_Number); //now on the variable"$string array repeat field" we have the feld number (the array number)

//if the number is found by preg_match, then put it into the $Numb_row variable and convert it to number instead of text
if ( isset($string_Number[0][0]) ) { $Numb_row_intval = intval(  $string_Number[0][0] ); } else {  $Numb_row_intval = null; } 

   




//----------MAKE ARRAY VALUE OF repeater field ----------------
//First of all let's see what's in the:

$ripetitore  = get_field($RIPETITORE_nome,  $product_id); //  exemple view array:   array(  array("url=>'video1'),array("url=>'video2'), );



// **** there must be at least one line (a url in the repeater). this is for when we edit an empty repeater ****
if($ripetitore != null && is_array( $ripetitore ) ){

     $value_repeat = $ripetitore;// repeater load
     $list_array_number_row  = array_map('intval', str_split($Numb_row_intval));

      if ( isset($list_array_number_row) ) {
          foreach($list_array_number_row as $nriga){
                   $keyArray = intval( $nriga);
                   if( $value_repeat[$keyArray] == '' || $value_repeat[$keyArray] == null  ){
                              $value_repeat[$keyArray] =  array("prodott_video_singolo_url" => null);
                      }
        }
      }
      
      if( $value == '' || $value == null) { unset( $value_repeat[$Numb_row_intval]);    } // If you want to delete the video, delete the video line
      else {  $value_repeat[$Numb_row_intval] = array("prodott_video_singolo_url" => $value); } //replace field values



// ****repeater does not exist, it has no lines and therefore the first one must be put ****
} else {
      $value_repeat = array();
      $list_array_number_row  = array_map('intval', str_split($Numb_row_intval));
      foreach($list_array_number_row as $nriga){
                  $keyArray = intval( $nriga);
                  $value_repeat[$keyArray] =  array("prodott_video_singolo_url" => null); 
      }

      // if the video value exists, and you are not making the field blank, then create the line
      if( $value !== '' || $value !== null) { $value_repeat[$Numb_row_intval] = array("prodott_video_singolo_url" => $value);  }

}
//------END ----MAKE ARRAY VALUE OF repeater field  ----------------






//----UPDATE REPEATER FIELD ACF----------------

update_field( $RIPETITORE_nome,$value_repeat, $product_id );

//*****************************************************



} //END  if(    $field_key )



//*****************************************************
return $value;
//*****************************************************

}, 12, 3);
============================================================================
================END ===FUNCTION ==============================================


hello guys

Hello

Great! Thank you for your cooperation!