Terra wallet plugin snippets WordPress / Woocommerce

remove cashback notice from shop page.

add_filter(‘woo_wallet_product_cashback_html’, ‘__return_false’);

disable wallet partial payment.

add_filter( ‘woo_wallet_disable_partial_payment’, ‘__return_true’ );

to view the wallet product.

add_filter(‘woo_wallet_hide_rechargeable_product’, ‘__return_false’);

to disable cashback if coupon applied in an order.

add_filter( ‘process_woo_wallet_general_cashback’, ‘process_woo_wallet_general_cashback_callback’, 10, 2 ); if ( ! function_exists( ‘process_woo_wallet_general_cashback_callback’ ) ) { /** * Disable cashback if coupon applied. * * @param bool $process * @param WC_Order $order * @return bool */ function process_woo_wallet_general_cashback_callback( $process, $order ) { if ( count( $order->get_coupon_codes() ) > 0 ) { $process = false; } return $process; } }

//correct

add_filter( 'woo_wallet_payment_is_available', 'woo_wallet_payment_is_available_callback', 10, 1 );

if ( ! function_exists( 'woo_wallet_payment_is_available_callback' ) ) {
	function woo_wallet_payment_is_available_callback( $is_available ) {
		if ( wc()->cart->has_discount() ) {
			$is_available = false;
		}
		return $is_available;
	}
}

add_filter( 'is_enable_wallet_partial_payment', 'is_enable_wallet_partial_payment_callback', 10, 1 );
if ( ! function_exists( 'is_enable_wallet_partial_payment_callback' ) ) {
	function is_enable_wallet_partial_payment_callback( $is_enable ) {
		if ( wc()->cart->has_discount() ) {
			$is_enable = false;
		}
		return $is_enable;
	}
}

For example when someone has at least 20 euro can use the wallet,if the amount is lower than20 , he cant.

add_filter( 'woo_wallet_payment_is_available', 'woo_wallet_payment_is_available_callback', 10, 1 );
if ( ! function_exists( 'woo_wallet_payment_is_available_callback' ) ) {
	function woo_wallet_payment_is_available_callback( $is_available ) {
		if ( woo_wallet()->wallet->get_wallet_balance( get_current_user_id(), 'edit' ) < 20 ) {
			$is_available = false;
		}
		return $is_available;
	}
}

add_filter( 'woo_wallet_disable_partial_payment', 'woo_wallet_disable_partial_payment_callback', 10, 1 );
if ( ! function_exists( 'woo_wallet_disable_partial_payment_callback' ) ) {
	function woo_wallet_disable_partial_payment_callback( $is_disabled ) {
		if ( woo_wallet()->wallet->get_wallet_balance( get_current_user_id(), 'edit' ) < 20 ) {
			$is_disabled = true;
		}
		return $is_disabled;
	}
}

display cashback amount at product page

add_shortcode( 'product-cashback', 'product_cashback_shortcode_output' );
if ( ! function_exists( 'product_cashback_shortcode_output' ) ) {
	function product_cashback_shortcode_output() {
		ob_start();
		$product = wc_get_product( get_the_ID() );
		if ( ! $product || is_wallet_account_locked() ) {
			return;
		}
		if ( $product->has_child() ) {
			$product = wc_get_product( current( $product->get_children() ) );
		}
		$cashback_amount = 0;
		if ( 'product' === woo_wallet()->settings_api->get_option( 'cashback_rule', '_wallet_settings_credit', 'cart' ) ) {
			$cashback_amount = woo_wallet()->cashback->get_product_cashback_amount( $product );
		} elseif ( 'product_cat' === woo_wallet()->settings_api->get_option( 'cashback_rule', '_wallet_settings_credit', 'cart' ) ) {
			$cashback_amount = woo_wallet()->cashback->get_product_category_wise_cashback_amount( $product );
		}
			$cashback_amount = apply_filters( 'woo_wallet_product_cashback_amount', $cashback_amount, get_the_ID() );
		if ( $cashback_amount ) {
			$cashback_html = '<span class="on-woo-wallet-cashback">' . wc_price( $cashback_amount, woo_wallet_wc_price_args() ) . __( ' Cashback', 'woo-wallet' ) . '</span>';
		} else {
			$cashback_html = '<span class="on-woo-wallet-cashback" style="display:none;"></span>';
		}
		echo apply_filters( 'woo_wallet_product_cashback_html', $cashback_html, get_the_ID() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		return ob_get_clean();
	}
}

To allow negative transactions please use the attached code in the theme functions.php file.

add_filter( ‘woo_wallet_disallow_negative_transaction’, ‘__return_false’ );

You can use our plugin hook process_woo_wallet_general_cashback to limit the cashback for specific WordPress user roles

unction limit_cashback_for_vendors($cashback_amount, $order, $user) { $user_info = get_userdata($user); // Check if the user is a vendor if (in_array(‘seller’, (array) $user_info->roles)) { // Set the cashback amount to 0 for vendors $cashback_amount = 0; } return $cashback_amount; } add_filter(‘process_woo_wallet_general_cashback’, ‘limit_cashback_for_vendors’, 10, 3);

We’d like to send wallet transaction data to another system. Is there a way to receive transaction data when there are new credits or debits?

You can use the woo_wallet_transaction_recorded action. This action have 4 argument: $transaction_id, $user_id, $amount, $typeThis is a sample to use this action:add_action( ‘woo_wallet_transaction_recorded’, ‘wallet_amount_change_notifier’, 10, 4 ); function wallet_amount_change_notifier( $transaction_id, $user_id, $amount, $type ) { if($type === ‘credit’){//do what you want in credit transaction} }

disable cashback if payment is made with wallet

add_filter(‘process_woo_wallet_general_cashback’, ‘process_woo_wallet_general_cashback_callback’, 5, 2); function process_woo_wallet_general_cashback_callback($process_cashback, $order) { if(‘wallet’ === $order->get_payment_method(‘edit’)) { return false; } return $process_cashback; }

add_filter(‘process_woo_wallet_general_cashback’, ‘process_woo_wallet_general_cashback_callback’, 5, 2); function process_woo_wallet_general_cashback_callback($process_cashback, $order) { if(‘wallet’ === $order->get_payment_method(‘edit’)) { return false; } return $process_cashback; }

Was this article helpful?
YesNo

Leave a Comment