php 点数按订单总价值奖励

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 点数按订单总价值奖励相关的知识,希望对你有一定的参考价值。

<?php
	/**
	 * Woo Point Rewards by Order Total
	 * Reward store purchases by paying a percentage of the order total
	 * as points to the buyer.
	 * @version 1.1
	 */
	function mycred_pro_reward_order_percentage( $order_id ) {

		if ( ! function_exists( 'mycred' ) ) return;

		// Get Order
		$order   = wc_get_order( $order_id );
		$cost    = $order->get_total();

		// Do not payout if order was paid using points
		if ( $order->payment_method == 'mycred' ) return;

		// The percentage to payout
		$percent = 100;

		// Load myCRED
		$mycred  = mycred();

		// Make sure user only gets points once per order
		if ( $mycred->has_entry( 'reward', $order_id, $order->user_id ) ) return;

		// Reward example 100% in points.
		$reward  = round($cost * ( $percent / 100 ));

		// Add reward
		$mycred->add_creds(
			'reward',
			$order->user_id,
			$reward,
			'Reward for MCC online store purchase',
			$order_id,
			array( 'ref_type' => 'post' )
		);

	}
	add_action( 'woocommerce_order_status_shipped', 'mycred_pro_reward_order_percentage' ); // woocommerce_order_status_<any order status>

以上是关于php 点数按订单总价值奖励的主要内容,如果未能解决你的问题,请参考以下文章

php 在特定订单状态之后奖励积分(在本例中为“已完成”)

PHP浮点数运算精度造成的,订单金额支付经常少1分的问题

SQL:编写查询按性别获取平均订单价值

php浮点数加减乘除bug

获取woocommerce获取订单总价值[重复]

如何根据总订单价值和邮政组获取报告