wooccm_update_attachmentids

The WooCommerce Checkout Manager wooccm update attachmentids function.

Description

wooccm_update_attachmentids( $order_id ); 

Parameters (1)

0. $order_id
The order id.

Usage

  1. if ( !function_exists( 'wooccm_update_attachmentids' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/main.php'; 
  3.  
  4. // The order id. 
  5. $order_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wooccm_update_attachmentids($order_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/classes/main.php  
  1. function wooccm_update_attachmentids( $order_id ) { 
  2.  
  3. $shipping = array( 'country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode' ); 
  4. $billing = array( 'country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode', 'email', 'phone' ); 
  5.  
  6. $names = array( 'billing', 'shipping' ); 
  7. $inc = 3; 
  8.  
  9. foreach( $names as $name ) { 
  10. $array = ($name == 'billing') ? $billing : $shipping; 
  11. $options = get_option( 'wccs_settings'.$inc.'' ); 
  12. foreach ( $options[''.$name.'_buttons'] as $btn ) : 
  13.  
  14. if ( !in_array( $btn['cow'], $array ) ) { 
  15. if( $btn['type'] == 'wooccmupload' ) { 
  16. $info = explode("||", get_post_meta( $order_id , '_'.$name.'_'.$btn['cow'].'', true)); 
  17. if( $info ) { 
  18. $new_info = explode( "||", $info[1] ); 
  19. foreach( $new_info as $image_id ) { 
  20. if( !empty($image_id ) ) { 
  21. wp_update_post( array( 'ID' => $image_id, 'post_parent' => $order_id )); 
  22. require_once( ABSPATH . 'wp-admin/includes/image.php' ); 
  23. wp_update_attachment_metadata( $image_id, wp_generate_attachment_metadata( $image_id, wp_get_attachment_url($image_id) ) ); 
  24. endforeach; 
  25. $inc--; 
  26.  
  27. $options = get_option( 'wccs_settings' ); 
  28. foreach ( $options['buttons'] as $btn ) : 
  29.  
  30. if( $btn['type'] == 'wooccmupload' ) { 
  31. $info = explode( "||", get_post_meta( $order_id , ''.$btn['cow'].'', true)); 
  32. if( $info ) { 
  33. $new_info = explode( "||", $info[1] ); 
  34. foreach( $new_info as $image_id ) { 
  35. if( !empty($image_id ) ) { 
  36. wp_update_post( array( 'ID' => $image_id, 'post_parent' => $order_id )); 
  37. require_once( ABSPATH . 'wp-admin/includes/image.php' ); 
  38. wp_update_attachment_metadata( $image_id, wp_generate_attachment_metadata( $image_id, wp_get_attachment_url($image_id) ) ); 
  39. endforeach;