woocommerce plugin bugs

时间:2016-11-16 作者:Cojocari Cristian

我在展示一些价值观方面有一些问题,我不知道我做错了什么。

    <?php
/*
 Plugin Name: Wallet for WooCommerce
 Plugin URI:
 Description: Wallet for a Client
 Version: 1.0
 Author: InDeepTerror
 Author URI:
 */

 include( plugin_dir_path( __FILE__ ) . \'wallet.php\');
include( plugin_dir_path( __FILE__ ) . \'settings.php\');


$wallet = New wallet();

 add_action( \'woocommerce_product_options_general_product_data\', \'getPerProduct\');

 add_action( \'woocommerce_process_product_meta\', \'save_wallet_option\');

?>

<?php
/***Class wallet**@param int$customer\\u id当前客户id**/

班级钱包{

function __construct()
{
        if ($this->checkEcommerce()) {
            add_filter( \'woocommerce_account_menu_items\', \'account_menu_hook\');
            add_filter( \'woocommerce_account_menu_items\', \'account_wallet_menu\');
            add_action( \'woocommerce_account_wallet-endpoint\', \'displayWallet\');
            add_action( \'wp_login\', \'walletOwner\', 99);
            add_action( \'woocommerce_created_customer\', \'createPointsField\');
} else
            throw new Exception(\'WooCommerce is not Installed. The plugin Requires WooCommerce\', 7);
}

function checkEcommerce() {
    if ( in_array( \'woocommerce/woocommerce.php\', apply_filters( \'active_plugins\', get_option( \'active_plugins\' ) ) ) ) {
        return true;
    }
    return false;
}

function walletOwner($login) {
$user = get_user_by(\'login\',$login);
    $user_id = $user->ID;
    return $user_id;
}

function displayWallet() {
/*    $userID = $this->walletOwner();
    $this->getUserPoints($userID);
echo "<span> <b>". $amount . "</b> </span>"
;*/
echo "TEST!";
}
function newMenuWP($pagetitle, $menu_title, $capability, $menu_slug, $function, $position, $icon_url) {
    add_menu_page( $pagetitle, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
}
function getPerPrice($percentage) {

}
function WPMenu(){
    echo \'\';
}
function getPerCategory($points) {

}
function getPerProduct() {
    global $woocommerce, $post;

    echo \'<div class="options_group">\';

    woocommerce_wp_text_input(
        array(
            \'id\'    => \'_number_field\',
            \'label\' => __( \'MoneyBack Wallet\', \'woocommerce\' ),
            \'placeholder\' => \'\',
            \'description\' => __( \'Enter the product percentage points\'),
            \'type\'        => \'number\',
            \'custom_attributes\' => array(
                \'step\' => \'0.1\',
                \'min\'  => \'0\',
                \'max\'  => \'100\',
            )
        )
    );

    echo \'</div>\';
}
function isAffiliate($product_id) {

}
function SignUpBonus($bonus) {

}
function setSignUpBonus($bonus_amount) {

}
function addPoints($add_points) {

}
function convertPoints($points)
{

}

function save_wallet_option()
{
    $woocommerce_number_field = $_POST[\'_number_field\'];
    if (!empty($woocommerce_number_field)) {
        update_post_meta($post_id, \'_number_field\', esc_attr($woocommerce_number_field));
    }
}
function account_menu_hook($items) {
$items[\'wallet-endpoint\'] = __(\'Wallet EndPoint\', \'woocommerce\');
    return $items;
}
function account_menu_insert_position($items, $new_items, $location) {
    $position = array_search( $after, array_keys( $items ) );
    $array = array_slice( $items, 0, $position, true );
    $array += $new_items;
    $array += array_slice( $items, $position, count( $items ) - $position, true );

    return $array;
}
function account_wallet_menu($items) {
    $new_items = array();
    $new_items[\'wallet-endpoint\'] = __(\'Wallet EndPoint\', \'woocommerce\');

    return $this->account_menu_insert_position($items, $new_items, \'dashboard\');
}
function getUserPoints($user_id) {

  $points = get_user_meta($user_id, \'points\', true);

  if (!isset($points)) {
      $this->createPointsField();
      return $points = $this->SignUpBonus();
  }

    return $points;
}
function createPointsField($customer_id) {
add_user_meta($customer_id, \'points\', $this->SignUpBonus());
}
}?>

我在添加新产品时遇到的错误:

警告:call\\u user\\u func\\u array()要求参数1是有效回调,在/home/styleadda/developers中找不到函数“getPerProduct”,或者函数名无效。styleadda。在/wp中包括/插件。php在线524

我在myaccount中遇到的错误:

警告:call\\u user\\u func\\u array()要求参数1为有效回调,在/home/styleadda/developers中找不到函数“account\\u menu\\u hook”,或函数名无效。styleadda。在/wp中包括/插件。php第235行

警告:call\\u user\\u func\\u array()要求参数1为有效回调,在/home/styleadda/developers中找不到函数“account\\u wallet\\u menu”,或函数名无效。styleadda。在/wp中包括/插件。php第235行

警告:为/home/styleadda/developers中的foreach()提供的参数无效。styleadda。在/wp-content/plugins/woocommerce/templates/myaccount/navigation中。php在线28

1 个回复
最合适的回答,由SO网友:Benoti 整理而成

如果要使用的函数在类中,则需要更正如何在类中为add\\u操作调用函数:add\\u操作(\'woocommerce\\u account\\u wallet-endpoint\',array($this,\'displayWallet\');add\\u action(\'wp\\u login\',array($this,\'walletOwner\'),99);

像这样替换所有add\\u操作或筛选器。