Woocommerce 如何创建terawallet产品\用户信用功能成功支付后的挂钩

Woocommerce 如何创建terawallet产品\用户信用功能成功支付后的挂钩,woocommerce,hook-woocommerce,Woocommerce,Hook Woocommerce,我正在运营woocommerce wordpress商店,并集成了一个名为“terawallet又名woo wallet”的虚拟钱包插件。此附加组件使站点上的每个用户都可以选择在结账时加满虚拟钱包、提取资金或将其用作付款方式 我想创建一个功能/挂钩,在购买产品时自动为产品作者钱包(发布产品帖子的用户)充值。我正在使用一个marketplace插件,为每个供应商/卖家设置佣金,在购买后,管理员获得佣金,卖家获得剩余(总卖家金额) 例如 用户1=卖方,用户2=买方 当买方购买产品时,卖方虚拟账户应在

我正在运营woocommerce wordpress商店,并集成了一个名为“terawallet又名woo wallet”的虚拟钱包插件。此附加组件使站点上的每个用户都可以选择在结账时加满虚拟钱包、提取资金或将其用作付款方式

我想创建一个功能/挂钩,在购买产品时自动为产品作者钱包(发布产品帖子的用户)充值。我正在使用一个marketplace插件,为每个供应商/卖家设置佣金,在购买后,管理员获得佣金,卖家获得剩余(总卖家金额)

例如 用户1=卖方,用户2=买方 当买方购买产品时,卖方虚拟账户应在产品订单完成(处理)后自动补足行政佣金后的剩余金额。因此,如果买家购买了属于4个不同产品作者的4个产品,那么每个作者都应该相应地计入与其用户ID链接的产品

woo wallet类称为“woo\u wallet\u wallet”

以下是贷记用户钱包的功能:

    /**
     * Create wallet payment credit transaction
     * @param int $user_id
     * @param float $amount
     * @param string $details
     * @return int transaction id
     */
    public function credit( $user_id = '', $amount = 0, $details = '' ) {
        $this->set_user_id( $user_id );
        return $this->recode_transaction( $amount, 'credit', $details );
    }
我尝试了以下代码:

$wallet = woo_wallet_wallet ();
$wallet ->credit($product_user_id,, (total_seller_amount), ‘credit’,)

您必须执行以下操作:

/**
 * Authomatically Top-up Multi vendor Woocommerce Seller on Complete order
 * @param int $order_id
 */
function izzycart_auto_topup_user_on_product_purchase( $order_id ) {
    $order = new WC_Order($order_id);

    /**
     * You may need order total and customer_id to compose 
     * Transaction message for top, which is why it is added
     * below as optional (if needed)
    */
    $total = $order->get_total(); // <=== Total order Price (if needed)
    $customer_id = $order->get_customer_id(); // <=== Customer ID (if needed)
    $order_items = $order->get_items(); // <=== Grab all items in order

    $item_details = [];

    foreach ( $order_items as $item ) {
        // Get the ID of each item in Order
        $product_id = $item->get_product_id();
        $item_details[] = [
            'product_name'  => $item->get_name(),
            'total'         => $item->get_total(),
            'author'        => get_post($product_id)->post_author // <=== The product/item author ID
        ];
    }

    //Loop through all product/items author and add topup their wallet
    foreach ($item_details as $item_detail) {
        $wallet = new Woo_Wallet_Wallet();

        // Get Administrator's percentage
        $adminsCut = 0.2 * $item_detail['total']; // <=== Admin Takes 20%

        // Get Author's Percentage
        $authorsCut = $item_detail['total'] - (0.2 * $item_detail['total']); // <=== Author Takes 80%

        //Top-Up Admin
        if( $item_detail['author'] != 1 ) {
             /**
             * By Default Administrator has an ID of 1
             * if Author of product is not Admin
            */
            $topUpAdmin = $wallet->credit(1, $adminsCut, "Top-Up cut from {$item_detail['product_name']} sales");

            //Top-Up Author of Product
            $topUpAuthor = $wallet->credit($item_detail['author'], $authorsCut, "Top-Up from {$item_detail['product_name']} purchase");
    }else {
            // Author of product is Admin. Give admin all the money
            $topUpAdmin = $wallet->credit(1, $item_detail['total'], "Top-Up from {$item_detail['product_name']} sales");
        }

    }
}
add_action( 'woocommerce_order_status_completed', 'izzycart_auto_topup_user_on_product_purchase', 10, 1 );
/**
*在完整订单上自动加满多供应商和商业卖家
*@param int$order\u id
*/
功能izzycart\u auto\u topup\u user\u on\u product\u purchase($order\u id){
$order=新WC\U订单($order\U id);
/**
*您可能需要订单总数和客户id来撰写
*top的事务消息,这就是添加它的原因
*以下为可选(如果需要)
*/
$total=$order->get_total();//get_customer_id();//get_items();//get_product_id();
$item_details[]=[
'product_name'=>$item->get_name(),
“总计”=>$item->get_total(),
'author'=>get_post('product_id)->post_author//credit($item_detail['author'],$authorsCut,“从{$item_detail['product_name']}购买中加满”);
}否则{
//该产品的作者是管理员。给管理员所有的钱
$topUpAdmin=$wallet->credit(1,$item_detail['total'],“从{$item_detail['product_name']}销售中充值”);
}
}
}
添加操作('woocommerce\u order\u status\u completed'、'izzycart\u auto\u topup\u user\u on\u product\u purchase',10,1);
测试和工作

管理员加满事务屏幕截图

产品补充交易屏幕截图的作者

WC版本:v4.5.2
Wordpress版本:v5.5.1
TeraWallet版本:v1.3.16

这段代码应该放在主题的function.php文件中