Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgatheviking/9150d64b000353c18beeadb8aa375083 to your computer and use it in GitHub Desktop.
Save helgatheviking/9150d64b000353c18beeadb8aa375083 to your computer and use it in GitHub Desktop.
WooCommerce Coupon Redemption Form Shortcode
<?php
/**
* Plugin Name: WC Coupon Redemption Form Shortcode
* Plugin URI: https://kathyisawesome.com/
* Description: Display coupon form with [fgc_form] shortcode
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Shortcode to enter gift code
*/
function fgc_gift_claim_form() {
if ( function_exists( 'wc_coupons_enabled' ) && wc_coupons_enabled() ) { ?>
<form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post">
<div class="actions">
<div class="coupon">
<label for="coupon_code"><?php esc_html_e( 'Coupon:', 'your-text-domain' ); ?></label>
<input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'your-text-domain' ); ?>" />
<button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Claim free gift', 'your-text-domain' ); ?>"><?php esc_attr_e( 'Claim Free Gift', 'your-text-domain' ); ?></button>
<?php do_action( 'woocommerce_cart_coupon' ); ?>
</div>
</div>
</form>
<?php } ?>
<?php
}
add_shortcode( 'fgc_form', 'fgc_gift_claim_form' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment