Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mooska

    (@mooska)

    I needed it working asap, next week might be too late 😉 sorry. Yes, its missing two fields, just wanted to get actually working version. If you have any tweaks, feel free, I’m not experienced with Broadcast api.

    Thread Starter mooska

    (@mooska)

    In the meantime, I did make it with filters. Leaving it in case someone looks for solution.

    
    function bc_threewp_broadcast_broadcasting_before_restore_current_blog( $action )
    {
    	$bcd = $action->broadcasting_data;  // Convenience.
    	
    	$cf = $bcd->custom_fields(); // Convenience.
    	
    	// Load the current fields.
    	$child_fields = $bcd->custom_fields()->child_fields();
    	$child_fields->load();
    	
    	// And now go through them, processing only arrays.
    	foreach( $child_fields as $custom_field => $values )
    	{
    		$value = reset( $values );
    		
    		$array = maybe_unserialize( $value );
    		
    		// We are only interested in arrays.
    		if ( ! is_array( $array ) )
    			continue;
    		
    		$type = '_bto_data';
    		
    		if( $custom_field == $type && $array) {
    			foreach( $array as $index=>$id ) {
    				foreach( $id['assigned_ids'] as $inner_index=>$assigned_id ) {
    					$converted_value  = ThreeWP_Broadcast()->get_post_broadcast_data( $bcd->parent_blog_id, $assigned_id );
    					if( $converted_value ) {
    						$child = $converted_value->get_linked_child_on_this_blog();
    						
    						if( $child ) {
    							$array[$index]['assigned_ids'][$inner_index]  = $child;
    						}
    					} else {
    						//
    					}
    				}
    			}
    			
    			$bcd->custom_fields()->child_fields()->update_meta( $custom_field, $array );
    		}
    		
    	}
    }
    
    add_action( 'threewp_broadcast_broadcasting_before_restore_current_blog', 'bc_threewp_broadcast_broadcasting_before_restore_current_blog' );
    Thread Starter mooska

    (@mooska)

    Yes, exactly, just bear in mind that asigned_ids might have several ids and default_id can be empty.

    Thank you!

    Thread Starter mooska

    (@mooska)

    Its official WC package:
    https://woocommerce.com/products/composite-products/

    The structure is pretty simple (its a private fields, so the meta name is _bto_data):

    [bto_data] => Array
    (
    [0] => Array
    (
    [group_id] => 1556369804
    [title] => Straps
    [position] => 0
    [description] =>
    [thumbnail_id] =>
    [query_type] => product_ids
    [assigned_ids] => Array
    (
    [0] => 794419
    )

    [default_id_categories] => 794419
    [default_id_products] => 794419
    [selection_mode] => dropdowns
    [pagination_style] => classic
    [quantity_min] => 1
    [quantity_max] => 1
    [discount] =>
    [display_prices] => absolute
    [show_product_title] => 1
    [show_product_description] => 1
    [show_product_thumbnail] => 1
    [show_product_price] => 1
    [show_subtotal_product] => 1
    [show_subtotal_cart] => 1
    [show_subtotal_orders] => 1
    )
    )

    In here its a single component (one element array) and product id is: 794419, so that should be straightforward. There can be several of those components. Im fighting with filters atm, but getting that first hand would be much appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)