首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress woocommerce interfax发送缺少字段的传真

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

Stack Overflow用户
提问于 2015-02-04 22:46:45
回答 1查看 681关注 0票数 0

我不是一个php程序员,我花了很长时间才弄清楚原因。希望能帮上忙。基本上,我安装了一个名为的woocommerce插件,用于向传真号码发送订单完成电子邮件。在文档中,它说插件使用订单完成模板发送传真。它确实包括订单电子邮件模板上的所有内容,除了保留订单备注字段外。我相信它一定与插件有关。也许它传递订单数组而不包括特定的order note字段?我不知道为什么,也不知道怎么解决。下面是interfax插件的源代码

代码语言:javascript
复制
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/' );
    }
EN

回答 1

Stack Overflow用户

发布于 2015-02-05 11:02:27

以下是在所有电子邮件的底部添加客户说明(这是订单帖子的“摘录”)的一个例子:

代码语言:javascript
复制
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 );
    }
}

woocommerce_email_after_order_table钩子在WooCommerce 2.3中是绝对可用的,但我认为它也可以在2.2+中使用。

或者,您可以将customer-completed-order.php模板复制到主题中,并直接处理它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28333042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档