简体   繁体   English

wordpress woocommerce interfax发送缺少字段的传真

[英]wordpress woocommerce interfax sends fax with a missing field

I am not a php programmer, and it takes me forever to figure out why. 我不是php程序员,这需要我永远找出原因。 So hopefully SO could help me out. 希望这样可以帮助我。 Basically, I installed a woocommerce plugin called interfax-woocommerce, which is used to send order completion email to fax number. 基本上,我安装了一个名为interfax-woocommerce的woocommerce插件,该插件用于将订单完成电子邮件发送到传真号码。 On the documentation, it says the plugin uses order completion template to send the fax. 在文档上,它说插件使用订单完成模板发送传真。 It does include everything on the order email template except leaving the order note field out. 它确实包括订单电子邮件模板上的所有内容,但不包括订单注释字段。 I believe it must have something to do with the plugin. 我相信它一定与插件有关。 maybe it passes the order array without including that particular order note field? 也许它通过订单数组而不包含特定的订单记录字段? I can not figure out why and how to fix it. 我不知道为什么以及如何解决它。 Below is the source code of interfax plugin 下面是interfax插件的源代码

if ( ! defined( 'ABSPATH' ) ) exit;

class WooCommerce_InterFax_Integration {
    private $dir;
    private $file;
    private $assets_dir;
    private $assets_url;
    private $settings;
    private $interfax_class;
    private $username;
    private $password;
    private $store_fax_number;
    private $template_html;
    private $heading;
    private $send_store_fax;
    private $order;
    private $fax_number;

    public function __construct( $file ) {
        $this->dir = dirname( $file );
        $this->file = $file;
        $this->assets_dir = trailingslashit( $this->dir ) . 'assets';
        $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $file ) ) );

        // Add settings link to plugin page
        add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'add_settings_link' ) );

        // Get integration settings
        $this->settings = get_option( 'woocommerce_interfax_settings' );

        // Only handle actions if integration is enabled
        if( $this->settings['wcif_enable'] == 'yes' ) {
            $this->interfax_class = 'http://ws.interfax.net/dfs.asmx?wsdl';
            $this->username = $this->settings['wcif_username'];
            $this->password = $this->settings['wcif_password'];
            $this->store_fax_number = $this->settings['wcif_fax_number'];
            $this->template_html = 'emails/customer-completed-order.php';
            $this->heading = __( 'Your order is complete', 'woocommerce' );
            $this->send_store_fax = true;

            // Add fax number field to checkout
            add_filter( 'woocommerce_checkout_fields', array( $this, 'add_checkout_field' ) );

            // Send fax on selected order status (deault to 'completed' if no status is selected)
            if( $this->settings['wcif_fax_status'] ) {
                $fax_status = $this->settings['wcif_fax_status'];
            } else {
                $fax_status = 'completed';
            }
            add_action( 'woocommerce_order_status_' . $fax_status, array( $this, 'trigger' ) );

            // Add order action to dashboard
            add_filter( 'woocommerce_order_actions', array( $this, 'add_order_action' ) );

            // Handle order actions
            add_action( 'woocommerce_order_action_send_customer_fax', array( $this, 'process_order_action_customer' ) );
            add_action( 'woocommerce_order_action_send_store_fax', array( $this, 'process_order_action_store' ) );

            // Add fax number field to user profile page in WP dashboard
            add_filter( 'woocommerce_customer_meta_fields', array( $this, 'add_user_meta_field' ) );

            // Add fax number field to edit billing address page
            add_filter( 'woocommerce_billing_fields', array( $this, 'add_address_field' ), 10, 2 );
        }

        // Handle localisation
        $this->load_plugin_textdomain();
        add_action( 'init', array( $this, 'load_localisation' ), 0 );

    }

    public function trigger( $order_id ) {
        if ( $order_id ) {
            $this->order = new WC_Order( $order_id );

            // Send fax to store owner
            if( $this->store_fax_number && strlen( $this->store_fax_number ) > 0 ) {
                $this->send_store_fax();
            }

            // Send fax to customer
            $this->fax_number = get_post_meta( $order_id, '_billing_fax', true );
            if( $this->fax_number && strlen( $this->fax_number ) > 0 ) {
                $this->send_customer_fax();
            }
        }
    }

    private function send_customer_fax() {
        $interfax_client = new SoapClient( $this->interfax_class );

        $params->Username  = $this->username;
        $params->Password  = $this->password;
        $params->FaxNumber = $this->fax_number;
        $params->Data      = $this->get_fax_content();
        $params->FileType  = 'HTML';

        $result = $interfax_client->SendCharFax( $params );

        if( isset( $result->SendCharFaxResult ) && $result->SendCharFaxResult > 0 ) {
            return true;
        }

        return false;
    }

    private function send_store_fax() {
        $interfax_client = new SoapClient( $this->interfax_class );

        $params->Username  = $this->username;
        $params->Password  = $this->password;
        $params->FaxNumber = $this->store_fax_number;
        $params->Data      = $this->get_fax_content();
        $params->FileType  = 'HTML';

        $result = $interfax_client->SendCharFax( $params );

        if( isset( $result->SendCharFaxResult ) && $result->SendCharFaxResult > 0 ) {
            return true;
        }

        return false;
    }

    public function get_fax_content() {
        global $woocommerce;

        ob_start();

        $template_data = array(
            'order'         => $this->order,
            'email_heading' => $this->heading
        );

        if( version_compare( $woocommerce->version, '2.1-beta-1', ">=" ) ) {
            wc_get_template( $this->template_html, $template_data );
        } else {
            woocommerce_get_template( $this->template_html, $template_data );
        }

        return ob_get_clean();
    }

    public function add_checkout_field( $fields ) {

        $fields['billing']['billing_fax'] = array(
            'label'             => __( 'Fax Number (including country code)', 'wc_interfax' ),
            'placeholder'       => _x( 'e.g. +27861234567', 'placeholder', 'wc_interfax' ),
            'required'          => false,
            'class'             => array( 'form-row' ),
            'clear'             => false
        );

        return $fields;

    }

    public function add_order_action( $actions ) {
        $actions['send_customer_fax'] = 'Send customer fax';
        $actions['send_store_fax']    = 'Send store fax';
        return $actions;
    }

    public function process_order_action_customer( $order ) {
        $this->fax_number = get_post_meta( $order->id, '_billing_fax', true );
        if( $this->fax_number && strlen( $this->fax_number ) > 0 ) {
            $this->order = $order;
            $this->send_customer_fax();
        }
    }

    public function process_order_action_store( $order ) {
        if( $this->store_fax_number && strlen( $this->store_fax_number ) > 0 ) {
            $this->order = $order;
            $this->send_store_fax();
        }
    }

    public function add_user_meta_field( $fields ) {

        $fields['billing']['fields']['billing_fax'] = array(
            'label' => __( 'Fax number', 'wc_interfax' ),
            'description' => ''
        );

        return $fields;

    }

    public function add_address_field( $fields, $country ) {

        $fields['billing_fax'] = array(
            'label'         => __( 'Fax Number (including country code)', 'wc_interfax' ),
            'placeholder'   => _x( 'e.g. +27861234567', 'placeholder', 'wc_interfax' ),
            'required'      => false,
            'class'         => array( 'form-row' ),
            'clear'         => true
        );

        return $fields;
    }

    public function add_settings_link( $links ) {
        $settings_link = '<a href="admin.php?page=woocommerce&tab=integration&section=interfax">' . __( 'Configure', 'wc_interfax' ) . '</a>';
        array_unshift( $links, $settings_link );
        return $links;
    }

    public function load_localisation () {
        load_plugin_textdomain( 'wc_interfax' , false , dirname( plugin_basename( $this->file ) ) . '/lang/' );
    }

    public function load_plugin_textdomain () {
        $domain = 'wc_interfax';
        $locale = apply_filters( 'plugin_locale' , get_locale() , $domain );

        load_textdomain( $domain , WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
        load_plugin_textdomain( $domain , FALSE , dirname( plugin_basename( $this->file ) ) . '/lang/' );
    }

Here is an example of adding the customer's note (which is the order post's "excerpt") to the bottom of all emails: 这是在所有电子邮件的底部添加客户注释(即订单过帐的“摘录”)的示例:

add_action( 'woocommerce_email_after_order_table' , 'so_28333042_add_customer_note' );
function so_28333042_add_customer_note( $order ){
    $post = get_post( $order->id );
    if( $post->post_excerpt != '' ){
        echo "<strong>Customer Note:</strong><br/>" . wp_kses_post( $post->post_excerpt );
    }
}

The woocommerce_email_after_order_table hook is definitely available in WooCommerce 2.3, but I think it is available in 2.2+ as well. woocommerce_email_after_order_table挂钩肯定在WooCommerce 2.3中可用,但我认为它在2.2+中也可用。

Alternatively, you could copy the customer-completed-order.php template into your theme and work directly on it. 另外,您可以将customer-completed-order.php模板复制到您的主题中并直接在其上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM