• Resolved atmanivedana

    (@atmanivedana)


    Hi guys, i’m developing a addon for yith Multi Vendor but i’m having problem with get_post_meta function, vendor cannot access to post_meta from order, in your plugin setting i have actived permission to vendor can change custom post fields in orders , so this is not a cause.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi there,
    I’m sorry but I don’t understand very well what you mean.
    Could you send me a screenshot as example to have a clear scenario about your request?
    Thank you for your cooperation.

    Thread Starter atmanivedana

    (@atmanivedana)

    Hi thanks for your response,
    Recently i found cause from this issue and it was because order in admin dasboard have a id different to id from child order, so when i tried access to order post_meta i got post_meta from admin order but not from vendor order. Both orders are independients and it have his self metas.
    So now my question is how can i add a post_meta via update_post_meta to child order and not to main order when a new order is made?, as this last is a default behavior.

    If i try update_post_meta ( $order_id , “any_post_meta” , “value” )
    This post meta will added to main order by default how can i add this to child order?.
    Thanks for your great plugin!

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,
    I understand what you say but if you use as $order_id the ID of the child order, the post meta value will be associated to the child order in database, not the parent order.
    Are you sure to use the child order ID?

    Thread Starter atmanivedana

    (@atmanivedana)

    Yes i tried do this and work, for example
    update_post_meta ( (int)$order_id + 1 , “any_post_meta” , “value” )
    Adding +1 to $order_id

    I hope that this post help to developers that have same problem.

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,
    yes, it can be a workaround because two orders are created together and the ID are consecutive.
    By the way you have to know that exists a method inside the class YITH_Orders that provides the suborder, using the parent order ID.

    public static function get_suborder( $parent_order_id = false, $check_created_via = false ) {
    			$suborder_ids = array();
    			if ( $parent_order_id ) {
    				global $wpdb;
    
    				$parent_ids = array( absint( $parent_order_id ) );
    
    				while ( $parent_ids ) {
    					$parent_list = implode( ',', $parent_ids );
    					$parent_ids  = $wpdb->get_col(
    						$wpdb->prepare( "SELECT ID 
                                             FROM {$wpdb->posts} 
                                             WHERE post_parent IN ({$parent_list}) 
                                             AND post_type=%s",
    							'shop_order'
    						)
    					);
    
    					$suborder_ids = array_merge( $suborder_ids, $parent_ids );
    				}
    			}
    
    			if( $check_created_via ){
    				foreach( $suborder_ids as $k => $suborder_id ){
    					$suborder = wc_get_order( $suborder_id );
    					$created_via = $suborder->get_created_via();
    					if( 'yith_wcmv_vendor_suborder' != $created_via ){
    						unset( $suborder_ids[ $k ] );
    					}
    				}
    			}
    
    			return apply_filters( 'yith_wcmv_get_suborder_ids', $suborder_ids, $parent_order_id );
    		}
    Thread Starter atmanivedana

    (@atmanivedana)

    Thanks, i have other question but i will post in other post. I will close this post.

    Plugin Author YITHEMES

    (@yithemes)

    You are welcome!

    If you like the plugin and our support, please, support us with a 5-star review.
    It takes just a minute.

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘get_post_meta to vendors not work’ is closed to new replies.