• Resolved termi

    (@termi)


    I created function that hoocks in to header of page to get ids of products on taxonomy page

    function woocommerce_acf_head_insert() {
    		$ids_list = array(0,0);
    		$count = 0;
    		while(have_posts() and $count < 2){
    		the_post();
    		$tmp = get_the_ID();  $ids_list[$count] = $tmp; $count += 1;	 }
    
    		// Sort array from lowest to highest
    		sort($ids_list);
    		echo $ids_list[0] . " " . $ids_list[1];
    
    			$value = get_field("resolution", $ids_list[0]); 
    			echo $value; 
    
    
    		if(!empty($ids_list[0])){
    		$value = get_field("resolution", $ids_list[1]); 
    		echo $value; 
    		}
    	} 

    Then i want to register function to create short code to use this ids extracted with function in header to call ACF custom field of “x product” wher x is number in array of extracted ids

    add_shortcode( 'acf_field', 'woocommerce_acf_shortcode' );
    
    function woocommerce_acf_shortcode( $atts, $ids_list) {
      $atts = shortcode_atts( array(
        'field_name' => '',
        'cont' => '',
      ), $atts, 'the_field' );
    
      $field_name = $atts['field_name'];
      $cont = $atts['cont'];
      $id = $ids_list[$cont];
      ob_start();
      echo $id;
      the_field( $field_name, $id );
      return ob_get_clean();
    }

    I use short code [acf_field field_name=”waterproof” cont=”0″] But i get warning : Warning: Uninitialized string offset 0 in \public\wp-content\plugins\Woocomerce ACF\Woocomerce ACF.php on line 310
    In line 310 is:

      $id = $ids_list[$cont];
    • This topic was modified 3 years, 4 months ago by termi.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Warning: Uninitialized string offset 0’ is closed to new replies.