Advertisement
verygoodplugins

Untitled

Feb 9th, 2020
18,729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. function my_wpf_export_options( $options ) {
  2.  
  3.     $options['zoho_deals'] = array(
  4.         'label'   => 'Zoho Deals',
  5.         'title'   => 'Orders',
  6.         'tooltip' => 'Finds WooCommerce orders that don\'t have a Zoho invoice ID and exports them to Zoho',
  7.     );
  8.  
  9.     return $options;
  10.  
  11. }
  12.  
  13. add_filter( 'wpf_export_options', 'my_wpf_export_options' );
  14.  
  15. function my_wpf_batch_init() {
  16.  
  17.     $args = array(
  18.         'numberposts' => - 1,
  19.         'post_type'   => 'shop_order',
  20.         'post_status' => array( 'wc-processing', 'wc-completed' ),
  21.         'fields'      => 'ids',
  22.         'order'       => 'ASC',
  23.         'meta_query'  => array(
  24.             array(
  25.                 'key'     => 'wpf_ec_zoho_invoice_id',
  26.                 'compare' => 'NOT EXISTS',
  27.             ),
  28.         ),
  29.     );
  30.  
  31.     $orders = get_posts( $args );
  32.  
  33.     wp_fusion()->logger->handle( 'info', 0, 'Beginning <strong>Zoho Deals</strong> batch operation on ' . count( $orders ) . ' orders', array( 'source' => 'batch-process' ) );
  34.  
  35.     return $orders;
  36.  
  37. }
  38.  
  39. add_action( 'wpf_batch_zoho_deals_init', 'my_wpf_batch_init' );
  40.  
  41. function my_wpf_batch_step( $order_id ) {
  42.  
  43.     $contact_id = get_post_meta( $order_id, wp_fusion()->crm->slug . '_contact_id', true );
  44.  
  45.     if ( empty( $contact_id ) ) {
  46.  
  47.         $order   = wc_get_order( $order_id );
  48.         $user_id = $order->get_user_id();
  49.  
  50.         if ( ! empty( $user_id ) ) {
  51.             $contact_id = wp_fusion()->user->get_contact_id( $user_id );
  52.         }
  53.     }
  54.  
  55.     if ( ! empty( $contact_id ) ) {
  56.  
  57.         wp_fusion_ecommerce()->integrations->woocommerce->send_order_data( $order_id, $contact_id );
  58.  
  59.     }
  60.  
  61. }
  62.  
  63. add_action( 'wpf_batch_zoho_deals', 'my_wpf_batch_step' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement