File manager - Edit - /home/aussies6/public_html/wp-content/plugins/order-delivery-date/integration.php
Back
<?php /** * Order Delivery Date Pro for WooCommerce * * Integration class to make the Order Delivery Date plugin compatible with various third party plugins. * * @author Tyche Softwares * @package Order-Delivery-Date-Pro-for-WooCommerce/Integration * @since 2.7 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } include_once( dirname( __FILE__ ) . '/orddd-common.php' ); /** * orddd_integration Class * * @class orddd_integration */ class orddd_integration { /** * Constructor. Adds various hooks and filters * based on the settings. */ public function __construct() { // Zapier integration add_action( 'plugins_loaded', array( 'orddd_integration', 'orddd_plugins_loaded' ) ); // WooCommerce PDF Invoices & Packing Slips if ( get_option( 'orddd_show_fields_in_pdf_invoice_and_packing_slips' ) == 'on' ) { if ( version_compare( get_option( 'wpo_wcpdf_version' ), '2.0.0', ">=" ) ) { add_action( 'wpo_wcpdf_after_order_details', array( 'orddd_integration', 'orddd_plugins_packing_slip' ), 10, 2 ); } else { add_action( 'wpo_wcpdf_after_order_details', array( 'orddd_integration', 'orddd_plugins_packing_slip' ) ); } } // add custom columns headers to csv when Order/Customer CSV Export Plugin is activate if ( get_option( 'orddd_show_fields_in_csv_export_check' ) == 'on' ) { add_filter( 'wc_customer_order_csv_export_order_headers', array( 'orddd_integration', 'wc_csv_export_modify_column_headers' ) ); add_filter( 'wc_customer_order_csv_export_order_row', array( 'orddd_integration', 'wc_csv_export_modify_row_data'), 10, 3 ); } //WooCommerce Print Invoice & Delivery Note if( get_option( 'orddd_show_fields_in_invoice_and_delivery_note' ) == 'on' ) { add_filter( 'wcdn_order_info_fields', array( 'orddd_integration', 'orddd_plugin_print_invoice_delivery_note' ), 10, 2 ); } if ( get_option( 'orddd_show_fields_in_cloud_print_orders' ) == 'on' ) { add_action( 'woocommerce_cloudprint_internaloutput_footer', array( 'orddd_integration', 'cloud_print_fields' ) ); } //WooCommerce Print Invoice/Packing list plugin add_action( 'wc_pip_after_body', array( 'orddd_integration', 'orddd_plugin_woocommerce_pip' ), 10, 4 ); //WooCommerce PDF Invoices plugin - Free and Premium add_action( 'wpi_after_formatted_shipping_address', array( 'orddd_integration', 'orddd_plugin_wpi' ), 10, 1 ); //WooCommerce Simply Order Export plugin add_filter( 'wpg_order_columns', array( 'orddd_integration', 'wpg_add_columns' ) ); add_filter( 'wc_settings_tab_order_export', array( 'orddd_integration', 'wpg_add_fields' ) ); add_action( 'wpg_add_values_to_csv', array( 'orddd_integration', 'csv_write' ), 10, 6 ); add_action( 'woocommerce_api_order_response', array( 'orddd_integration', 'woocommerce_api_create_order' ), 10, 4 ); } /** * Adds the Delivery Details to the WooCommerce API * * @param array $order_data - Order Data * @param WC_Order $order - Order Details * @param array $fields - Request fields. * @param object $server * @return array $order_data - Updated Order Data with Delivery details. * * @hook woocommerce_api_order_response * @since 5.8 */ public static function woocommerce_api_create_order( $order_data, $order, $fields, $server ) { if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $order->get_id(); } else { $order_id = $order->id; } $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { $order_data[ $locations_label ] = $address; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); if( $delivery_date_formatted != '' ) { $order_data[ get_option( 'orddd_delivery_date_field_label' ) ] = $delivery_date_formatted; } if( get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ) , true ) ) { $order_data[ get_option( 'orddd_delivery_timeslot_field_label' ) ] = get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true ); } if( get_post_meta( $order_id, '_orddd_timestamp' , true ) ) { $order_data[ '_orddd_timestamp' ] = get_post_meta( $order_id, '_orddd_timestamp', true ); } return $order_data; } /** * Executed during the 'plugins_loaded' WordPress hook. * * - Load Supported Zapier Triggers * * @hook plugins_loaded * @since 2.7 */ public static function orddd_plugins_loaded() { if ( class_exists( 'WC_Zapier' ) ) { $trigger_keys = array( 'wc.new_order', // New Order 'wc.order_status_change' // New Order Status Change ); foreach ( $trigger_keys as $trigger_key ) { add_filter( "wc_zapier_data_{$trigger_key}", array('orddd_integration', 'orddd_order_data_override' ), 10, 4 ); } } } /** * When sending WooCommerce Order data to Zapier, also send order delivery date field * that have been created by the Order Delivery Date plugin. * * @param array $order_data - Order data that will be overridden. * @param WC_Zapier_Trigger $trigger - Trigger that initiated the data send. * @return array $order_data - Updated Order data with delivery details. * * @since 2.7 */ public static function orddd_order_data_override( $order_data, WC_Zapier_Trigger $trigger ) { $field_name = get_option( 'orddd_delivery_date_field_label' ); $time_slot = get_option( 'orddd_delivery_timeslot_field_label' ); $locations_label = get_option( 'orddd_location_field_label' ); if ( $trigger->is_sample() ) { // We're sending sample data. // Send the label of the custom checkout field as the field's value. $order_data[ $field_name ] = $field_name; $order_data[ $time_slot ] = $time_slot; $order_data[ $locations_label ] = $locations_label; } else { // We're sending real data. // Send the saved value of this checkout field. // If the order doesn't contain this custom field, an empty string will be used as the value. $order_data[ $field_name ] = get_post_meta( $order_data[ 'id' ], $field_name, true ); $order_data[ $time_slot ] = get_post_meta( $order_data[ 'id' ], $time_slot, true ); $order_data[ $locations_label ] = get_post_meta( $order_data[ 'id' ], $locations_label, true ); } return $order_data; } /** * Adds delivery date and time selected for an order in the PDF invoices * and Packing slips from WooCommerce PDF Invoices & Packing Slips plugin. * * @param string $template_type - Template Type for the Invoice * @param array $order - Order data * * @hook wpo_wcpdf_after_order_details * @since 2.7 */ public static function orddd_plugins_packing_slip( $template_type = "", $order = array() ) { global $orddd_date_formats; if ( version_compare( get_option( 'wpo_wcpdf_version' ), '2.0.0', ">=" ) ) { $order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; } else { global $wpo_wcpdf; $order_export = $wpo_wcpdf->export; $order_obj = $order_export->order; $order_id = $order_obj->id; } $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { echo '<p><strong>' . __( $locations_label, 'order-delivery-date' ) . ': </strong>' . $address; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); if( $delivery_date_formatted != '' ) { echo '<p><strong>' . __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted; } $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id ); if( $order_page_time_slot != "" && $order_page_time_slot != '' ) { echo '<p><strong>' . __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot; } } /** * Adds delivery date and time column headings to CSV when order * is exported from Order/Customer CSV Export Plugin. * * @param array $column_headers - List of Column Names * @return array $column_headers - The list of column names * * @hook wc_customer_order_csv_export_order_headers * @since 2.7 */ public static function wc_csv_export_modify_column_headers( $column_headers ) { $new_headers = array( 'column_1' => __( get_option( 'orddd_location_field_label' ), 'order-delivery-date' ), 'column_2' => __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ), 'column_3' => __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ), ); return array_merge( $column_headers, $new_headers ); } /** * Adds delivery date and time column content to CSV when order * is exported from Order/Customer CSV Export Plugin. * * @param array $order_data - * @param object $order - Order Details * @param object $csv_generator * @return array $new_order_data - Delivery data * * @hook wc_customer_order_csv_export_order_row * @since 2.7 */ public static function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) { $new_order_data = array(); if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $order->get_id(); } else { $order_id = $order->id; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); $custom_data = array( 'column_1' => $address, 'column_2' => $delivery_date_formatted, 'column_3' => get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true ), ); $new_order_data = array(); $one_row_per_item = false; if ( version_compare( wc_customer_order_csv_export()->get_version(), '4.0.0', '<' ) ) { // pre 4.0 compatibility $one_row_per_item = ( 'default_one_row_per_item' === $csv_generator->order_format || 'legacy_one_row_per_item' === $csv_generator->order_format ); } elseif ( isset( $csv_generator->format_definition ) ) { // post 4.0 (requires 4.0.3+) $one_row_per_item = 'item' === $csv_generator->format_definition['row_type']; } if ( $one_row_per_item ) { foreach ( $order_data as $data ) { $new_order_data[] = array_merge( (array) $data, $custom_data ); } } else { $new_order_data = array_merge( $order_data, $custom_data ); } return $new_order_data; } /** * Adds delivery date and time selected for an order in the invoices * and delivery notes from WooCommerce Print Invoice & Delivery Note plugin. * * @param array $fields - List of fields * @param object $order - Order data * @return array $fields - with the delivery data added * * @hook wcdn_order_info_fields * @since 2.7 */ public static function orddd_plugin_print_invoice_delivery_note( $fields, $order ) { $new_fields = array(); if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $order->get_id(); } else { $order_id = $order->id; } $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { $new_fields[ $locations_label ] = array( 'label' => __( $locations_label, 'order-delivery-date' ), 'value' => $address ); } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); if( $delivery_date_formatted != '' ) { $new_fields[ get_option( 'orddd_delivery_date_field_label' ) ] = array( 'label' => __( get_option( 'orddd_delivery_date_field_label' ), 'order-delivery-date' ), 'value' => $delivery_date_formatted ); } if( get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ) , true ) ) { $new_fields[ get_option( 'orddd_delivery_timeslot_field_label' ) ] = array( 'label' => __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ), 'value' => get_post_meta( $order_id, get_option( 'orddd_delivery_timeslot_field_label' ), true ) ); } return array_merge( $fields, $new_fields ); } /** * Adds delivery date and time selected for an order * in the prints from WooCommerce Print Orders plugin. * * @param object $order - Order Details * * @hook woocommerce_cloudprint_internaloutput_footer * @since 2.7 */ public static function cloud_print_fields( $order ) { $field_date_label = get_option( 'orddd_delivery_date_field_label' ); if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $order->get_id(); } else { $order_id = $order->id; } $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { echo '<p><strong>' . __( $locations_label, 'order-delivery-date' ) . ': </strong>' . $address; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); echo '<p><strong>'.__( $field_date_label, 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted; $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id ); if( $order_page_time_slot != "" && $order_page_time_slot != '' ) { echo '<p><strong>' . __( get_option( 'orddd_delivery_timeslot_field_label' ), 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot; } } /** * Adds delivery date and time selected for an order in the invoices * and delivery notes from WooCommerce Print Invoice/Packing list plugin. * * @param string $type * @param string $action * @param string $document * @param resource $order Order Details * * @hook wc_pip_after_body * @todo Need to check the type of the parameters. * * @since 2.7 */ public static function orddd_plugin_woocommerce_pip( $type, $action, $document, $order ) { global $orddd_date_formats; $delivery_date = get_option( 'orddd_delivery_date_field_label' ); $time_slot = get_option( 'orddd_delivery_timeslot_field_label' ); if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $order->get_id(); } else { $order_id = $order->id; } $locations_label = get_option( 'orddd_location_field_label' ); $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { echo '<p><strong>' . __( $locations_label, 'order-delivery-date' ) . ': </strong>' . $address; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); if( $delivery_date_formatted != '' ) { echo '<p><strong>' . __( $delivery_date, 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted; } $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id ); if( $order_page_time_slot != "" && $order_page_time_slot != '' ) { echo '<p><strong>' . __( $time_slot, 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot; } } /** * Adds delivery date and time selected for an order in the invoices * from WooCommerce PDF Invoices Premium plugin. * * @param resource $order Invoice Details * * @hook wpi_after_formatted_shipping_address * * @since 9.6 */ public static function orddd_plugin_wpi( $invoice ) { $delivery_date = get_option( 'orddd_delivery_date_field_label' ); $time_slot = get_option( 'orddd_delivery_timeslot_field_label' ); $locations_label = get_option( 'orddd_location_field_label' ); if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) { $order_id = $invoice->order->get_id(); } else { $order_id = $invoice->order->id; } $address = get_post_meta( $order_id, $locations_label, true ); if( $address != '' ) { echo '<p><strong>' . __( $locations_label, 'order-delivery-date' ) . ': </strong>' . $address; } $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); if( $delivery_date_formatted != '' ) { echo '<p><strong>' . __( $delivery_date, 'order-delivery-date' ) . ': </strong>' . $delivery_date_formatted; } $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id ); if( $order_page_time_slot != "" && $order_page_time_slot != '' ) { echo '<p><strong>' . __( $time_slot, 'order-delivery-date' ) . ': </strong>' . $order_page_time_slot; } } /** * Adds Delivery date and/or time column in CSV export file * for WooCommerce Simply Order Export plugin. * * @param array $cols - Column Names * @return array $cols - Updated Column Names * * @hook wpg_order_columns * @since 4.0 */ public static function wpg_add_columns( $cols ) { $locations_label = get_option( 'orddd_location_field_label' ); $delivery_date_label = get_option( 'orddd_delivery_date_field_label' ); $time_slot_label = get_option( 'orddd_delivery_timeslot_field_label' ); $cols[ 'orddd_pickup_location' ] = $locations_label; $cols[ 'orddd_delivery_date' ] = $delivery_date_label; $cols[ 'orddd_time_slot' ] = $time_slot_label; return $cols; } /** * Adds Delivery date and/or time field display settings on the * Settings page for WooCommerce Simply Order Export plugin * * @param array $settings - Settings * @param array $settings - Updated with Delivery field settings * * @hook wc_settings_tab_order_export * @since 4.0 */ public static function wpg_add_fields( $settings ) { $delivery_date_label = get_option( 'orddd_delivery_date_field_label' ); $time_slot_label = get_option( 'orddd_delivery_timeslot_field_label' ); $locations_label = get_option( 'orddd_location_field_label' ); $settings[ 'Pickup Location' ] = array( 'name' => $locations_label, 'type' => 'checkbox', 'desc' => __( 'Pickup Location', 'order-delivery-date' ), 'id' => 'orddd_pickup_location' ); $settings[ 'Delivery Date' ] = array( 'name' => $delivery_date_label, 'type' => 'checkbox', 'desc' => __( 'Delivery Date', 'order-delivery-date' ), 'id' => 'orddd_delivery_date' ); $settings[ 'Time Slot' ] = array( 'name' => $time_slot_label, 'type' => 'checkbox', 'desc' => __( 'Time Slot', 'order-delivery-date' ), 'id' => 'orddd_time_slot' ); return $settings; } /** * Adds Delivery date and/or time details in CSV export file * for WooCommerce Simply Order Export plugin. * * @hook wpg_add_values_to_csv * * @param array $csv Values to export to CSV * @param resoruce $od Order Object * @param string $field Field slug * @param string $key * @param string $item_id * @param array $current_item * * @since 4.0 */ public static function csv_write( &$csv, $od, $field, $key, $item_id, $current_item ) { $order_id = $od->id; $address = get_post_meta( $order_id, $locations_label, true ); $delivery_date_formatted = orddd_common::orddd_get_order_delivery_date( $order_id ); $order_page_time_slot = orddd_common::orddd_get_order_timeslot( $order_id ); switch( $field ) { case 'orddd_delivery_date': array_push( $csv, $delivery_date_formatted ); break; case 'orddd_time_slot': array_push( $csv, $order_page_time_slot ); break; case 'orddd_pickup_location': array_push( $csv, $address ); break; default : break; } } } $orddd_integration = new orddd_integration(); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings