Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function my_wpf_export_options( $options ) {
- $options['zoho_deals'] = array(
- 'label' => 'Zoho Deals',
- 'title' => 'Orders',
- 'tooltip' => 'Finds WooCommerce orders that don\'t have a Zoho invoice ID and exports them to Zoho',
- );
- return $options;
- }
- add_filter( 'wpf_export_options', 'my_wpf_export_options' );
- function my_wpf_batch_init() {
- $args = array(
- 'numberposts' => - 1,
- 'post_type' => 'shop_order',
- 'post_status' => array( 'wc-processing', 'wc-completed' ),
- 'fields' => 'ids',
- 'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'wpf_ec_zoho_invoice_id',
- 'compare' => 'NOT EXISTS',
- ),
- ),
- );
- $orders = get_posts( $args );
- wp_fusion()->logger->handle( 'info', 0, 'Beginning <strong>Zoho Deals</strong> batch operation on ' . count( $orders ) . ' orders', array( 'source' => 'batch-process' ) );
- return $orders;
- }
- add_action( 'wpf_batch_zoho_deals_init', 'my_wpf_batch_init' );
- function my_wpf_batch_step( $order_id ) {
- $contact_id = get_post_meta( $order_id, wp_fusion()->crm->slug . '_contact_id', true );
- if ( empty( $contact_id ) ) {
- $order = wc_get_order( $order_id );
- $user_id = $order->get_user_id();
- if ( ! empty( $user_id ) ) {
- $contact_id = wp_fusion()->user->get_contact_id( $user_id );
- }
- }
- if ( ! empty( $contact_id ) ) {
- wp_fusion_ecommerce()->integrations->woocommerce->send_order_data( $order_id, $contact_id );
- }
- }
- add_action( 'wpf_batch_zoho_deals', 'my_wpf_batch_step' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement