• I know you can use the shortcode to display the theme template but is there a way to display the actual voucher? This would be the icing on the cake for me with this plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chris Taylor

    (@mrwiblog)

    This isn’t possible at the moment as the vouchers are only created at the time they are downloaded.

    Thread Starter John Thomas

    (@heirani1)

    ah right ok. An update in a future release maybe? In the meantime do you know of any way around this so I can have the image of the voucher and then when the image is clicked it can be downloaded?

    Hi Guys.. I wanted to do the same thing.. so i hacked the code a little by using a div…

    Here is the code as it exists:

    // process a shortcode for a voucher
    function voucher_do_voucher_shortcode( $atts ) {
    	extract( shortcode_atts( array(
    		'id' => '',
    		'preview' => ''
    	), $atts ) );
    	if ( $id != "" ) {
    		$voucher = voucherpress_get_voucher( $id );
    		if ( $voucher && ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) {
    			if ( $preview == 'true' ) {
    				return '<a href="' . voucherpress_link( $voucher->guid ) . '"><code></code><img src="' . get_option( "siteurl" ) . '/wp-content/plugins/voucherpress/templates/' . $voucher->template . '_thumb.jpg" alt="' . htmlspecialchars( $voucher->name ) . '" /></a>';
    			} else {
    				return '<a href="' . voucherpress_link( $voucher->guid ) . '">' . htmlspecialchars( $voucher->name ) . '</a>';
    			}
    		} else {
    			$r = "<!-- The shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed";
    			if ( $voucher ) {
    				$r .= ". Voucher found, expiry: '" . $voucher->expiry . "'";
    			}
    			$r .= " -->";
    			return $r;
    		}
    	}
    }

    Here is the modified code:

    // process a shortcode for a voucher
    function voucher_do_voucher_shortcode( $atts ) {
    	extract( shortcode_atts( array(
    		'id' => '',
    		'preview' => ''
    	), $atts ) );
    	if ( $id != "" ) {
    		$voucher = voucherpress_get_voucher( $id );
    		if ( $voucher && ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) {
    			if ( $preview == 'true' ) {
    				return '<a href="' . voucherpress_link( $voucher->guid ) . '"><div style="position: absolute; width:400; height:0;">' . htmlspecialchars( $voucher->name ) . '</div><img src="' . get_option( "siteurl" ) . '/wp-content/plugins/voucherpress/templates/' . $voucher->template . '_thumb.jpg" alt="' . htmlspecialchars( $voucher->name ) . '" /></a>';
    			} else {
    				return '<a href="' . voucherpress_link( $voucher->guid ) . '">' . htmlspecialchars( $voucher->name ) . '</a>';
    			}
    		} else {
    			$r = "<!-- The shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed";
    			if ( $voucher ) {
    				$r .= ". Voucher found, expiry: '" . $voucher->expiry . "'";
    			}
    			$r .= " -->";
    			return $r;
    		}
    	}
    }

    The above worked for me… you can see an example at https://www.korma-sutra.com on the sidebar under section called vouchers…

    With a little more styling one can make it look better… I just did a quick and dirty.. but it works.. It uses the voucher title as the text to display ontop of the image of the voucher… essentially creating the appearance of a preprinted voucher…

    Thread Starter John Thomas

    (@heirani1)

    Hi Korma Sutra, yours only displays the first line of the voucher though, not the whole voucher. Is this achievable? if so how would it be done.

    Thanks mate.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: VoucherPress] display voucher including text?’ is closed to new replies.