Woocommerce呼叫网址(完成订单后) [英] Woocommerce call url (after complete order)

查看:53
本文介绍了Woocommerce呼叫网址(完成订单后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个问题(需要帮助):


  1. 我不知道如何运行此程序插件(给我致命错误),请检查我的脚本(我是初学者)

  2. 需要管理页面帮助来设置APIkey并选择呼叫网址的语言 http://xxx.CZ http://xxx.SK (此页面尚未编写脚本)

  3. 如何将我的插件管理页面添加到woocommerce管理页面?

  1. I do not know, how to run this plugin (gives me fatal error) please check my script (I am beginner)
  2. Need help with admin page to set up APIkey and choose language for call url http://xxx.CZ or http://xxx.SK (This page is not scripted yet)
  3. How to add my plugin admin page to woocommerce admin page?

此插件用于Woocommerce。应该调用特定的URL (http://heureka.cz/或.sk / dotaznik /在woocommerce的管理页面中设置的客户端API //客户电子邮件 /订单ID / 定购商品ID /),当客户订购si时完成。

This plugin is for Woocommerce. It is supposed to call specific URL (http://heureka.cz/or .sk/dotaznik/"Clients API set up in admin page in woocommerce"/"Customers email"/"Order ID"/"bought Products ID"/) when customers order si complete.

我是PHP和Wordpress的初学者。谢谢大家的帮助。

I am beginner in PHP and Wordpress. Thank you all for helping me.

代码:

<?php
/*
Plugin Name: Overené zákazníkmi Heureka
Plugin URI: http://www.podujatie.eu
Version: 0.1
Description: 
Author: Podujatie.eu, Ing. Igor Kóňa
Tested up to: 3.6
Author URI: http://www.podujatie.eu
Text Domain: woocommerce-new-badge
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
 * Check if WooCommerce is active
 **/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

    if ( ! class_exists( 'WC_HO' ) ) {

        class WC_HO {

        function heurekaovereno( $order_id ) {     
        error_log( "Order complete for order $order_id", 0 ); } 
        add_action( 'woocommerce_order_status_completed', 'heurekaovereno' );

    // order object (optional but handy)
    $order = new WC_Order( $order_id );

    // do some stuff here
        private function sendRequest($url)
        {
        $parsed = parse_url($url);
        $fp = fsockopen($parsed['host'], 80, $errno, $errstr, 5);
        if (!$fp) {
            throw new HeurekaOverenoException($errstr . ' (' . $errno . ')');
            } else {
            $return = '';
            $out = "GET " . $parsed['path'] . "?" . $parsed['query'] . " HTTP/1.1\r\n" .
                    "Host: " . $parsed['host'] . "\r\n" .
                    "Connection: Close\r\n\r\n";
            fputs($fp, $out);
            while (!feof($fp)) {
                $return .= fgets($fp, 128);
            }
            fclose($fp);
            $returnParsed = explode("\r\n\r\n", $return);

            return empty($returnParsed[1]) ? '' : trim($returnParsed[1]);
            }
        }
        /**
     * Sends request to Heureka Overeno service and checks for valid response
     * 
     * @return boolean true
     */
    public function send()
        {
        if (empty($this->email)) {
            throw new HeurekaOverenoException('Customer email address not set');
        }

        // create URL
        $url = $this->getUrl() . '?id=' . $this->apiKey . '&email=' . urlencode($this->email);
        foreach ($this->products as $product) {
            $url .= '&produkt[]=' . urlencode($product);
            }
        foreach ($this->productsItemId as $itemId) {
            $url .= '&itemId[]=' . urlencode($itemId);
            }

        // add order ID
        if (isset($this->orderId)) {
            $url .= '&orderid=' . urlencode($this->orderId);
            }

        // send request and check for valid response
        $contents = $this->sendRequest($url);
        if ($contents == FALSE) {
            throw new HeurekaOverenoException('Unable to create HTTP request to Heureka Overeno service');
            } elseif ($contents == self::RESPONSE_OK) {
            return TRUE;
            } else {
            throw new HeurekaOverenoException($contents);
            }
        }
        /**
     * Adds ordered products using item ID
     *
     * @param string $itemId Ordered product item ID
     */
    public function addProductItemId($itemId)
    {
        $this->productsItemId[] = $itemId;
    }
        /**
     * Adds ordered products using name
     * 
     * Products names should be provided in UTF-8 encoding. The service can handle
     * WINDOWS-1250 and ISO-8859-2 if necessary
     *
     * @param string $productName Ordered product name
     */
    public function addProduct($productName)
    {
        $this->products[] = $productName;
    }
        /**
     * Heureka endpoint URL
     *
     * @var string     
     */
    const BASE_URL = 'http://www.heureka.cz/direct/dotaznik/objednavka.php';
    const BASE_URL_SK = 'http://www.heureka.sk/direct/dotaznik/objednavka.php';

    /**
     * Language IDs
     *
     * @var int     
     */
    const LANGUAGE_CZ = 1;
    const LANGUAGE_SK = 2;
    /**
     * Valid response value
     *
     * @var string     
     */
    const RESPONSE_OK = 'ok';

    /**
     * Shop API key
     *
     * @var string     
     */
    private $apiKey;

    /**
     * Customer email
     *
     * @var string     
     */
    private $email;

    /**
     * Ordered products
     *
     * @var array     
     */
    private $products = array();

    /**
     * Order ID
     *
     * @var int    
     */
    private $orderId;

    /**
     * Current language identifier
     *
     * @var int     
     */
    private $languageId = 1;

    /**
     * Ordered products provided using item ID
     * 
     * @var array
     */
    private $productsItemId = array();

    /**
     * Initialize Heureka Overeno service 
     *
     * @param string $apiKey Shop API key
     * @param int $languageId Language version settings
     */
    public function __construct($apiKey, $languageId = self::LANGUAGE_CZ)
    {
        $this->setApiKey($apiKey);
        $this->languageId = $languageId;
    }

    /**
     * Sets API key and check well-formedness
     * 
     * @param string $apiKey Shop api key
     */
    public function setApiKey($apiKey)
    {
        if (preg_match('(^[0-9abcdef]{32}$)', $apiKey)) {
            $this->apiKey = $apiKey;
        } else {
            throw new OverflowException('Api key ' . $apiKey . ' is invalid.');
        }
    }

    /**
     * Sets customer email
     *
     * @param string $email Customer email address
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    // Default options
    add_option( 'wc_nb_newness', '30' );


    // Admin
    add_action( 'woocommerce_settings_image_options_after', array( $this, 'admin_settings' ), 20);
    add_action( 'woocommerce_update_options_catalog', array( $this, 'save_admin_settings' ) );



            /*-----------------------------------------------------------------------------------*/
            /* Class Functions */
            /*-----------------------------------------------------------------------------------*/

            // Load the settings
            function admin_settings() {
                woocommerce_admin_fields( $this->settings );
            }


            // Save the settings
            function save_admin_settings() {
                woocommerce_update_options( $this->settings );
            }

        if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];

        $heurekaovereno_ver = '1.00';

        $WC_HO = new WC_HO();
        }
    }
}
?>


推荐答案

此脚本有效(虽然有一些错误,但它有效)仅当您将其放入functions.php
我在这里问,为什么呢?

This script works (it has few bugs, but it works) only when you put it in functions.php Here is where I am asking, why is it.

这篇关于Woocommerce呼叫网址(完成订单后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆