Home / eCommerce / Fix coupon displaying 0% in the affiliate dashboard
Duplicate Snippet

Embed Snippet on Your Site

Fix coupon displaying 0% in the affiliate dashboard

Code Preview
php
<?php
add_filter( 'get_post_metadata', function( $value, $object_id, $meta_key, $single ) {
	static $running = false;
	if ( $running ) {
		return $value;
	}
	$intercepted = array( '_mepr_coupons_discount_amount', '_mepr_coupons_discount_type' );
	if ( ! in_array( $meta_key, $intercepted, true ) ) {
		return $value;
	}
	if ( 'memberpresscoupon' !== get_post_type( $object_id ) ) {
		return $value;
	}
	$running       = true;
	$discount_mode = get_post_meta( $object_id, '_mepr_coupons_discount_mode', true );
	$running       = false;
	if ( 'first-payment' !== $discount_mode ) {
		return $value;
	}
	$running = true;
	if ( '_mepr_coupons_discount_amount' === $meta_key ) {
		$result = get_post_meta( $object_id, '_mepr_coupons_first_payment_discount_amount', true );
	} else {
		$result = get_post_meta( $object_id, '_mepr_coupons_first_payment_discount_type', true );
	}
	$running = false;
	return $single ? $result : array( $result );
}, 10, 4 );

Comments

Add a Comment