Below, you’ll find a detailed guide on how to add the Woo Coupon Usage Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Woo Coupon Usage Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Woo Coupon Usage Plugin and the shortcodes it provides:
"WooCommerce Affiliate Plugin – Coupon Affiliates is a must-have tool for online retailers. It empowers you to track coupon usage in your WooCommerce store, enhancing your affiliate marketing strategy."
- [wcusage_customer_edit_account_html]
- [couponaffiliates-referrer]
- [couponaffiliates-my-coupons]
- [couponaffiliates-referral-urls]
- [couponusage]
- [couponusage-user]
- [couponaffiliates-register]
Woo Coupon Usage [wcusage_customer_edit_account_html] Shortcode
The ‘wcusage_customer_edit_account_html’ shortcode from the Woo-Coupon-Usage plugin allows users to edit their account details. It extracts the ‘text’ attribute from the shortcode and returns an ‘Edit Account’ form. The form uses the ‘myaccount/form-edit-account.php’ template and populates it with the current user’s information.
Shortcode: [wcusage_customer_edit_account_html]
Parameters
Here is a list of all possible wcusage_customer_edit_account_html shortcode parameters and attributes:
text
– The label for the ‘Edit Account’ button
Examples and Usage
Basic example – A simple usage of the ‘wcusage_customer_edit_account_html’ shortcode. This shortcode will display the ‘Edit Account’ form for the currently logged in user.
[wcusage_customer_edit_account_html /]
Advanced examples
Customizing the shortcode to display a different text instead of the default ‘Edit Account’. This can be achieved by adding the ‘text’ attribute to the shortcode and assigning it a new value.
[wcusage_customer_edit_account_html text="Update Your Account" /]
Another advanced usage can be to pass more than one parameter to the shortcode. However, since our function doesn’t support more than one parameter, we can modify our function to accept more parameters. Here’s an example:
function wcusage_customer_edit_account_html_shortcode( $atts ) {
// Attributes
extract( shortcode_atts( array(
'text' => 'Edit Account',
'button_text' => 'Save Changes' ), $atts ) );
return wc_get_template_html( 'myaccount/form-edit-account.php', array( 'user' => get_user_by( 'id', get_current_user_id() ), 'button_text' => $button_text ) );
}
Now, we can use the shortcode with two parameters like this:
[wcusage_customer_edit_account_html text="Update Your Account" button_text="Submit Changes" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wcusage_customer_edit_account_html]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wcusage_customer_edit_account_html', 'wcusage_customer_edit_account_html_shortcode' );
Shortcode PHP function:
function wcusage_customer_edit_account_html_shortcode( $atts ) {
// Attributes
extract( shortcode_atts( array(
'text' => 'Edit Account' ), $atts ) );
return wc_get_template_html( 'myaccount/form-edit-account.php', array( 'user' => get_user_by( 'id', get_current_user_id() ) ) );
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-general.php
Woo Coupon Usage [couponaffiliates-referrer] Shortcode
The ‘couponaffiliates-referrer’ shortcode retrieves the referrer’s details from a cookie or user meta. It allows customization of the returned text and type. .
Shortcode: [couponaffiliates-referrer]
Parameters
Here is a list of all possible couponaffiliates-referrer shortcode parameters and attributes:
text
– The custom message to display before the referrer information.type
– Determines if spaces in the output should be replaced with ‘%20’ for URLs.
Examples and Usage
Basic example – Utilizing the shortcode to display the referrer information without any additional text or formatting.
[couponaffiliates-referrer /]
Advanced examples
1. Using the shortcode to display the referrer information with additional text. The text will be displayed before the referrer information.
[couponaffiliates-referrer text="Your referrer is: " /]
2. Using the shortcode to display the referrer information with additional text and formatting it as a URL. The text will be displayed before the referrer information and both will be formatted as a URL.
[couponaffiliates-referrer text="Your referrer is: " type="url" /]
Note: The ‘type’ attribute can be used to format the output. If the ‘type’ is set to ‘url’, the output will be formatted as a URL. If the ‘type’ is not set or is set to any other value, the output will be displayed as plain text.
PHP Function Code
In case you have difficulties debugging what causing issues with [couponaffiliates-referrer]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponaffiliates-referrer', 'wcusage_couponusage_referrer_shortcode' );
Shortcode PHP function:
function wcusage_couponusage_referrer_shortcode( $atts ) {
$atts = shortcode_atts( array(
'text' => '',
'type' => '',
), $atts, 'couponaffiliates-referrer' );
$the_text = "";
$return_string = "";
$user_id = get_current_user_id();
if(isset($_COOKIE['wcusage_referral'])) {
$cookie = $_COOKIE['wcusage_referral'];
} else {
$cookie = "";
}
$cookie = sanitize_text_field($cookie);
$wcu_lifetime_referrer = get_user_meta( $user_id, 'wcu_lifetime_referrer', true );
if($wcu_lifetime_referrer) { $cookie = $wcu_lifetime_referrer; }
if($cookie) {
$the_text = sanitize_text_field(esc_html($atts['text']));
$return_string = $the_text . " " . $cookie;
if($atts['type'] == "url") {
$the_text = str_replace(' ', '%20', $the_text);
$return_string = str_replace(' ', '%20', $return_string);
}
}
return $return_string;
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-shortcode-extra.php
Woo Coupon Usage [couponaffiliates-my-coupons] Shortcode
The ‘couponaffiliates-my-coupons’ shortcode is used to display the titles of all the coupons a user has. It retrieves the coupon IDs associated with the current user and loops through them to output the titles.
Shortcode: [couponaffiliates-my-coupons]
Examples and Usage
Basic example – The shortcode ‘couponaffiliates-my-coupons’ is used to display the titles of all the coupons owned by the current logged-in user.
[couponaffiliates-my-coupons /]
Advanced examples
There are no additional parameters available for this shortcode. The shortcode ‘couponaffiliates-my-coupons’ does not support any additional parameters. It uses the current logged-in user’s ID to fetch and display the titles of all the coupons owned by the user. Therefore, no advanced usage examples can be provided for this shortcode.
Please note, the given PHP code does not provide any attributes or parameters to modify the shortcode output. If you need to add additional parameters or attributes, you’ll need to modify the PHP function ‘wcusage_couponusage_my_coupons_shortcode’. For example, if you want to limit the number of coupon titles displayed, you could add a ‘limit’ attribute to the function and use it in the foreach loop to break the loop after displaying the specified number of coupon titles. This would require advanced PHP and WordPress development skills, and is beyond the scope of this article. If you need assistance with this, consider hiring a professional WordPress developer.PHP Function Code
In case you have difficulties debugging what causing issues with [couponaffiliates-my-coupons]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponaffiliates-my-coupons', 'wcusage_couponusage_my_coupons_shortcode' );
Shortcode PHP function:
function wcusage_couponusage_my_coupons_shortcode( $atts ) {
$coupon_ids = wcusage_get_users_coupons_ids( get_current_user_id() );
$i = 0;
ob_start();
foreach($coupon_ids as $coupon) {
$i++;
if($i > 1) { echo ", "; }
echo get_the_title($coupon);
}
$return_string = ob_get_clean();
return $return_string;
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-shortcode-extra.php
Woo Coupon Usage [couponaffiliates-referral-urls] Shortcode
The ‘couponaffiliates-referral-urls’ shortcode generates referral URLs for each coupon a user has. It appends the coupon title to a default URL or home URL.
Shortcode: [couponaffiliates-referral-urls]
Examples and Usage
Basic example – A simple usage of the ‘couponaffiliates-referral-urls’ shortcode without any additional parameters. This will display the referral URLs for the coupons of the current logged in user.
[couponaffiliates-referral-urls /]
PHP Function Code
In case you have difficulties debugging what causing issues with [couponaffiliates-referral-urls]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponaffiliates-referral-urls', 'wcusage_couponusage_referral_urls_shortcode' );
Shortcode PHP function:
function wcusage_couponusage_referral_urls_shortcode( $atts ) {
$coupon_ids = wcusage_get_users_coupons_ids( get_current_user_id() );
$wcusage_field_default_ref_url = trailingslashit( wcusage_get_setting_value('wcusage_field_default_ref_url', get_home_url() ) );
$wcusage_urls_prefix = wcusage_get_setting_value('wcusage_field_urls_prefix', 'coupon');
$i = 0;
ob_start();
foreach($coupon_ids as $coupon) {
$i++;
$url = $wcusage_field_default_ref_url . "?" . $wcusage_urls_prefix . "=" . get_the_title($coupon);
?>
<a href="<?php echo $url; ?>"><?php echo $url; ?></a>
<?php
if($i > 1) { echo "<br/>"; }
}
$return_string = ob_get_clean();
return $return_string;
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-shortcode-extra.php
Woo Coupon Usage [couponusage] Shortcode
The Woo-Coupon-Usage plugin shortcode ‘couponusage’ allows you to track and display coupon usage statistics. This shortcode triggers the ‘wcusage_couponusage’ function, which fetches data about how often a specific coupon has been used. This helps you gauge the effectiveness of your discounts and promotions.
Shortcode: [couponusage]
Examples and Usage
Basic example – The basic usage of the shortcode ‘couponusage’ without any parameters. This will display the default coupon usage statistics.
[couponusage /]
Advanced examples
Display coupon usage statistics for a specific coupon by specifying the coupon ID. If the coupon ID is not found, it will display an error message.
[couponusage id=1 /]
Display coupon usage statistics for a specific coupon by specifying the coupon code. If the coupon code is not found, it will display an error message.
[couponusage code="WINTER20" /]
Display coupon usage statistics for a specific coupon and limit the number of usage displayed. This can be used to show only the top usage statistics.
[couponusage code="WINTER20" limit=10 /]
Display coupon usage statistics for a specific coupon and specify the date range. This can be used to show usage statistics for a specific period.
[couponusage code="WINTER20" start_date="2020-01-01" end_date="2020-12-31" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [couponusage]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponusage', 'wcusage_couponusage' );
Shortcode PHP function:
f
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-shortcode.php
Woo Coupon Usage [couponusage-user] Shortcode
The Woo Coupon Usage shortcode is used to fetch user-specific coupon data. It generates a list of coupons assigned to a currently logged-in user. This shortcode, when implemented, checks if a user is logged in. If not, it prompts them with a login form. For logged-in users, it retrieves the number of coupons assigned to them. If no coupons are found, a message is displayed. If coupons are found, it displays them in a list format, providing details like discount type, usage count, and a link to the coupon dashboard.
Shortcode: [couponusage-user]
Examples and Usage
Basic example – Display the list of coupons for the current user.
[couponusage-user]
Advanced examples
Display the list of coupons for a specific user by passing the user ID as a parameter. In this case, the user ID is 5.
[couponusage-user id="5"]
Display the list of coupons for a specific user and limit the number of coupons displayed. In this case, we are displaying the coupons for the user with ID 5 and limiting the number of coupons to 10.
[couponusage-user id="5" limit="10"]
PHP Function Code
In case you have difficulties debugging what causing issues with [couponusage-user]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponusage-user', 'wcusage_getUserCouponList' );
Shortcode PHP function:
function wcusage_getUserCouponList()
{
ob_start();
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
$args = array(
'post_type' => 'shop_coupon',
'posts_per_page' => -1,
'meta_key' => 'wcu_select_coupon_user',
'meta_value' => $current_user_id,
);
$options = get_option( 'wcusage_options' );
$obituary_query = new WP_Query( $args );
$numcoupons = $obituary_query->post_count;
$urlid = "";
if ( is_array( $obituary_query ) ) {
$countamount = count( $obituary_query );
}
$wcusage_justcoupon = wcusage_get_setting_value( 'wcusage_field_justcoupon', '1' );
$wcusage_registration_enable = wcusage_get_setting_value( 'wcusage_field_registration_enable', '1' );
$wcusage_loginform = wcusage_get_setting_value( 'wcusage_field_loginform', '1' );
$wcusage_registration_enable_login = wcusage_get_setting_value( 'wcusage_field_registration_enable_login', '1' );
$wcusage_registration_enable_logout = wcusage_get_setting_value( 'wcusage_field_registration_enable_logout', '1' );
$wcusage_show_coupon_if_single = wcusage_get_setting_value( 'wcusage_field_show_coupon_if_single', '1' );
$wcusage_field_form_style = wcusage_get_setting_value( 'wcusage_field_form_style', '3' );
$wcusage_field_form_style_columns = wcusage_get_setting_value( 'wcusage_field_form_style_columns', '1' );
if ( isset( $_GET['couponid'] ) ) {
$urlid = $_GET['couponid'];
}
if ( $urlid ) {
echo do_shortcode( '[couponaffiliates coupon="' . $urlid . '"]' ) ;
} else {
?>
<h3 class="wcu-user-coupon-title"><?php
echo esc_html__( "Your Coupons", "woo-coupon-usage" ) ;
?> (<?php
echo $numcoupons ;
?>)</h3>
<hr class="wcu-user-coupon-linebreak" />
<?php
if ( !is_user_logged_in() ) {
// Get Login Form
if ( $wcusage_loginform ) {
ob_start();
?>
<style>.wcu-user-coupon-title { display: none; }</style>
<div class="wcusage-login-form-cols">
<?php
if ( $wcusage_registration_enable && $wcusage_registration_enable_login && $wcusage_registration_enable_logout ) {
?>
<div class="wcusage-login-form-col wcu_form_style_<?php
echo $wcusage_field_form_style ;
if ( $wcusage_field_form_style_columns ) {
?> wcu_form_style_columns<?php
}
?>">
<?php
}
?>
<div class="wcu-form-section">
<p class="wcusage-login-form-title" style="font-size: 1.2em;"><strong><?php
echo esc_html__( 'Login', 'woo-coupon-usage' ) ;
?>:</strong></p>
<div class="wcusage-login-form-section">
<?php
if ( function_exists( 'wc_print_notices' ) ) {
woocommerce_output_all_notices();
}
if ( function_exists( 'woocommerce_login_form' ) ) {
woocommerce_login_form();
}
?>
</div>
</div>
<?php
if ( $wcusage_registration_enable && $wcusage_registration_enable_login && $wcusage_registration_enable_logout ) {
?>
</div>
<?php
}
?>
<?php
if ( $wcusage_registration_enable && $wcusage_registration_enable_login && $wcusage_registration_enable_logout ) {
echo "<div class='wcusage-login-form-col'>" ;
echo do_shortcode( '[couponaffiliates-register]' ) ;
echo "</div>" ;
}
?>
</div>
<?php
return ob_get_clean();
} else {
echo esc_html__( "No affiliate dashboard found. Please contact us.", "woo-coupon-usage" ) ;
if ( current_user_can( 'administrator' ) ) {
echo "<br/><br/><strong>Admin message:</strong><br/>To get started, go to the '<strong><a href='" . admin_url( "admin.php?page=wcusage_coupons" ) . "'>coupons list</a></strong>' in your dashboard, where you can find a list of the affiliate dashboard URLs." ;
}
}
} else {
if ( !$numcoupons ) {
echo "<p>" . esc_html__( "Sorry, you don't currently have any active affiliate coupons.", "woo-coupon-usage" ) . "</p>" ;
$wcusage_field_registration_enable_register_loggedin = wcusage_get_setting_value( 'wcusage_field_registration_enable_register_loggedin', '1' );
if ( $wcusage_field_registration_enable_register_loggedin ) {
echo "<br/>" ;
echo do_shortcode( '[couponaffiliates-register]' ) ;
}
}
$countcoupons = 0;
$countcouponsloop = 0;
$lastcoupon = "";
while ( $obituary_query->have_posts() ) {
$obituary_query->the_post();
$postid = get_the_ID();
$coupon = get_the_title();
$secretid = $coupon . "-" . $postid;
$uniqueurl = wcusage_get_coupon_shortcode_page( 1 ) . 'couponid=' . $secretid;
if ( $numcoupons <= 1 && $wcusage_show_coupon_if_single ) {
if ( wcusage_iscouponusers( $coupon, $current_user_id ) && $lastcoupon != $coupon ) {
$coupon = str_replace( ' ', '%20', $coupon );
// Fix spaces
echo do_shortcode( "[couponaffiliates coupon=" . $coupon . "]" ) ;
echo "<style>.admin-only-list-coupons, .wcu-user-coupon-title, .wcu-user-coupon-linebreak { display: none; }</style>" ;
}
$lastcoupon = $coupon;
} else {
$select_coupon_user = get_post_meta( $postid, 'wcu_select_coupon_user', true );
//echo $current_user_id . " - " . $select_coupon_user . "<br/>";
if ( get_the_title() ) {
$countcoupons++;
$countcouponsloop++;
if ( $countcouponsloop == 1 ) {
echo "<div class='wcu-user-coupon-list-group'>" ;
}
echo "<div class='wcu-user-coupon-list'>" ;
echo "<h3>" . get_the_title() . "</h3>" ;
$amount = get_post_meta( $postid, 'coupon_amount', true );
$discount_type = get_post_meta( $postid, 'discount_type', true );
$combined_commission = wcusage_commission_message( $postid );
if ( $discount_type == "percent" ) {
$discount_msg = $amount . "%";
} elseif ( $discount_type == "recurring_percent" ) {
$discount_msg = $amount . "% (" . esc_html__( 'Recurring', 'woo-coupon-usage' ) . ")";
} elseif ( $discount_type == "fixed_cart" ) {
$discount_msg = wcusage_get_currency_symbol() . $amount;
} else {
$discount_msg = $amount . " (" . $discount_type . ")";
}
echo '<p>' . esc_html__( "Discount", "woo-coupon-usage" ) . ': ' . $discount_msg . '</p>' ;
//$orders = wcusage_wh_getOrderbyCouponCode( get_the_title(), '0000-00-00', date( "Y-m-d" ), '', 1 );
//$usage = $orders['total_count'];
global $woocommerce ;
$c = new WC_Coupon( get_the_title() );
$usage = $c->get_usage_count();
if ( $usage === "" ) {
$usage = '0';
}
$wcu_alltime_stats = get_post_meta( $postid, 'wcu_alltime_stats', true );
if ( !empty($wcu_alltime_stats['total_count']) ) {
$usage = $wcu_alltime_stats['total_count'];
}
echo '<p>' . esc_html__( "Total Usage", "woo-coupon-usage" ) . ': ' . $usage . '</p>' ;
echo '<p>' . esc_html__( "Commission", "woo-coupon-usage" ) . ': ' . $combined_commission . '</p>' ;
echo '<p style="margin: 0 0 10px 0;"><a class="wcu-coupon-list-button" href="' . $uniqueurl . '">' . esc_html__( 'Dashboard', 'woo-coupon-usage' ) . ' <i class="far fa-arrow-alt-circle-right"></i></a></p>' ;
echo "</div>" ;
if ( $countcouponsloop == 3 ) {
echo "</div>" ;
$countcouponsloop = 0;
}
}
}
}
if ( $countcouponsloop != 3 ) {
echo "</div>" ;
}
}
echo "<div style='clear: both;'></div>" ;
}
$thecontent = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
return $thecontent;
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/functions/functions-user-coupons.php
Woo Coupon Usage [couponaffiliates-register] Shortcode
The Woo Coupon Usage shortcode is responsible for creating and managing the affiliate registration form. It handles user input validation, form submission, and error handling. It also integrates reCAPTCHA for added security. .
Shortcode: [couponaffiliates-register]
Examples and Usage
Basic example – Display the registration form for the affiliate program using the shortcode.
[couponaffiliates-register /]
Advanced examples
Customize the registration form by passing parameters to the shortcode. For instance, you can enable or disable the logout option, captcha, and terms and conditions acceptance. You can also set the recaptcha keys and secret, as well as customize the terms message.
[couponaffiliates-register wcusage_field_registration_enable_logout="0" wcusage_registration_enable_captcha="1" wcusage_registration_recaptcha_key="your_recaptcha_key" wcusage_registration_recaptcha_secret="your_recaptcha_secret" wcusage_field_registration_enable_terms="1" wcusage_field_registration_terms_message="I accept the terms and conditions." /]
Note: Replace “your_recaptcha_key” and “your_recaptcha_secret” with your actual reCAPTCHA key and secret.
PHP Function Code
In case you have difficulties debugging what causing issues with [couponaffiliates-register]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'couponaffiliates-register', 'wcusage_couponusage_register' );
Shortcode PHP function:
function wcusage_couponusage_register( $atts )
{
ob_start();
$options = get_option( 'wcusage_options' );
$current_user_id = get_current_user_id();
$user_info = get_userdata( $current_user_id );
$wcusage_registration_enable_logout = wcusage_get_setting_value( 'wcusage_field_registration_enable_logout', '1' );
$wcusage_field_registration_enable = wcusage_get_setting_value( 'wcusage_field_registration_enable', '1' );
$enable_captcha = wcusage_get_setting_value( 'wcusage_registration_enable_captcha', '' );
$wcusage_registration_recaptcha_key = wcusage_get_setting_value( 'wcusage_registration_recaptcha_key', '' );
$wcusage_registration_recaptcha_secret = wcusage_get_setting_value( 'wcusage_registration_recaptcha_secret', '' );
$wcusage_registration_turnstile_key = wcusage_get_setting_value( 'wcusage_registration_turnstile_key', '' );
$wcusage_registration_turnstile_secret = wcusage_get_setting_value( 'wcusage_registration_turnstile_secret', '' );
$wcusage_field_registration_emailusername = wcusage_get_setting_value( 'wcusage_field_registration_emailusername', '0' );
$wcusage_field_registration_enable_terms = wcusage_get_setting_value( 'wcusage_field_registration_enable_terms', '' );
$wcusage_field_registration_terms_message = wcusage_get_setting_value( 'wcusage_field_registration_terms_message', 'I have read and agree to the Affiliate Terms and Privacy Policy.' );
$wcusage_registration_enable_admincan = wcusage_get_setting_value( 'wcusage_field_registration_enable_admincan', '0' );
$auto_coupon = "";
$auto_coupon_format = "";
?>
<?php
if ( is_page() ) {
?>
<?php
do_action( 'wcusage_hook_custom_styles' );
// Custom Styles
?>
<?php
}
?>
<?php
if ( isset( $_POST['wcusage_submit_registration_form1'] ) && isset( $_POST['submitaffiliateapplication'] ) ) {
if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wcusage_submit_registration_form1'] ) ), 'wcusage_verify_submit_registration_form1' ) || is_user_logged_in() ) {
echo wcusage_post_submit_application( 0 ) ;
}
}
if ( isset( $_SESSION["wcu_registration_token"] ) ) {
unset( $_SESSION["wcu_registration_token"] );
}
?>
<!-- Recaptcha -->
<?php
if ( $enable_captcha == "1" && isset( $options['wcusage_registration_recaptcha_key'] ) && !wp_script_is( 'g-recaptcha', 'enqueued' ) ) {
wp_enqueue_script(
'g-recaptcha',
'https://www.google.com/recaptcha/api.js',
array(),
'1.0.0',
true
);
}
?>
<!-- Turnstile -->
<?php
if ( $enable_captcha == "2" && isset( $options['wcusage_registration_turnstile_key'] ) && !wp_script_is( 'cf-turnstile', 'enqueued' ) ) {
wp_enqueue_script(
'cf-turnstile',
'https://challenges.cloudflare.com/turnstile/v0/api.js',
array(),
'1.0.0',
true
);
}
?>
<?php
if ( !wcusage_is_customer_blacklisted() ) {
?>
<?php
if ( is_user_logged_in() || $wcusage_registration_enable_logout && $wcusage_field_registration_enable ) {
?>
<div class="wcu-form-section<?php
?> wcu-form-section-free<?php
?>">
<?php
// Form Title
$wcusage_field_registration_form_title = wcusage_get_setting_value( 'wcusage_field_registration_form_title', '' );
if ( $wcusage_field_registration_form_title ) {
$form_title = $wcusage_field_registration_form_title;
} else {
$form_title = esc_html__( 'Register New Affiliate Account', 'woo-coupon-usage' );
}
?>
<p class="wcusage-register-form-title" style="font-size: 1.2em;"><strong><?php
echo esc_html( $form_title ) ;
?>:</strong></p>
<link rel="stylesheet" href="<?php
echo WCUSAGE_UNIQUE_PLUGIN_URL . 'fonts/font-awesome/css/all.min.css' ;
?>" crossorigin="anonymous">
<?php
// Disable form for existing affiliates?
$disable_existing = wcusage_get_setting_value( 'wcusage_field_registration_disable_existing', '1' );
$is_existing_affiliate = 0;
if ( $disable_existing ) {
$users_coupons = wcusage_get_users_coupons_ids( $current_user_id );
if ( !empty($users_coupons) ) {
$is_existing_affiliate = 1;
}
}
?>
<?php
if ( is_user_logged_in() ) {
global $wpdb ;
$table_name = $wpdb->prefix . 'wcusage_register';
$existing = $wpdb->get_row( "SELECT * FROM " . $table_name . " WHERE userid = " . $current_user_id . " AND status = 'pending' ORDER BY id DESC" );
} else {
$existing = 0;
}
// Check if user already has active application
if ( empty($existing) || wcusage_check_admin_access() && $wcusage_registration_enable_admincan ) {
?>
<?php
// Get template coupon code
$registration_coupon_template = wcusage_get_setting_value( 'wcusage_field_registration_coupon_template', '' );
$wcusage_field_form_style = wcusage_get_setting_value( 'wcusage_field_form_style', '3' );
$wcusage_field_form_style_columns = wcusage_get_setting_value( 'wcusage_field_form_style_columns', '1' );
$name_required = wcusage_get_setting_value( 'wcusage_field_registration_name_required', '0' );
$field_password_confirm = wcusage_get_setting_value( 'wcusage_field_registration_password_confirm', '0' );
$get_template_coupon = wcusage_get_coupon_info( $registration_coupon_template );
?>
<?php
if ( !$is_existing_affiliate || wcusage_check_admin_access() && $wcusage_registration_enable_admincan ) {
?>
<!-- Form -->
<div class="wcu_form_style_<?php
echo esc_html( $wcusage_field_form_style ) ;
if ( $wcusage_field_form_style_columns ) {
?> wcu_form_style_columns<?php
}
?>">
<form method="post" class="wcu_form_affiliate_register" enctype="multipart/form-data">
<?php
if ( is_user_logged_in() && (!$wcusage_registration_enable_admincan && wcusage_check_admin_access() || !wcusage_check_admin_access()) ) {
?>
<p class="wcu-register-field-col-username"><label for="wcu-input-username"><?php
echo esc_html__( 'Username', 'woo-coupon-usage' ) ;
?>:</label>
<input type="text" id="wcu-input-username" name="wcu-input-username" class="input-text form-control" value="<?php
echo esc_html( $user_info->user_login ) ;
?>" style="max-width: 300px;" disabled>
</p>
<?php
} else {
?>
<p class="wcu-register-field-col wcu-register-field-col-1"><label for="wcu-input-first-name"><?php
echo esc_html__( 'First Name', 'woo-coupon-usage' ) ;
?>:<?php
if ( $name_required ) {
?>*<?php
}
?></label>
<input type="text" id="wcu-input-first-name" name="wcu-input-first-name" class="input-text form-control" value="" style="max-width: 300px;" <?php
if ( $name_required ) {
?>required<?php
}
?>>
</p>
<p class="wcu-register-field-col wcu-register-field-col-2"><label for="wcu-input-last-name"><?php
echo esc_html__( 'Last Name', 'woo-coupon-usage' ) ;
?>:<?php
if ( $name_required ) {
?>*<?php
}
?></label>
<input type="text" id="wcu-input-last-name" name="wcu-input-last-name" class="input-text form-control" value="" style="max-width: 300px;" <?php
if ( $name_required ) {
?>required<?php
}
?>>
</p>
<?php
if ( !$wcusage_field_registration_emailusername ) {
?>
<p class="wcu-register-field-col-username wcu-register-field-col-1"><label for="wcu-input-username"><?php
echo esc_html__( 'Username', 'woo-coupon-usage' ) ;
?>:*</label>
<input type="text" id="wcu-input-username" name="wcu-input-username" class="input-text form-control" value="" style="max-width: 300px;" required>
</p>
<?php
}
?>
<p class="wcu-register-field-col-email <?php
if ( !$wcusage_field_registration_emailusername ) {
?>wcu-register-field-col-2<?php
}
?>"><label for="wcu-input-email"><?php
echo esc_html__( 'Email Address', 'woo-coupon-usage' ) ;
?>:*</label>
<input type="email" id="wcu-input-email" name="wcu-input-email" class="input-text form-control" value="" style="max-width: 300px;" required>
</p>
<p class="wcu-register-field-col-password<?php
if ( $field_password_confirm ) {
?> wcu-register-field-col-1<?php
}
?>"><label for="wcu-input-password"><?php
echo esc_html__( 'Password', 'woo-coupon-usage' ) ;
?>:*</label>
<input type="password" id="wcu-input-password" name="wcu-input-password" class="input-text form-control" value="" style="max-width: 300px; display: inline-block;" required>
</p>
<?php
if ( $field_password_confirm ) {
?>
<p class="wcu-register-field-col-password-confirm<?php
if ( $field_password_confirm ) {
?> wcu-register-field-col-2<?php
}
?>"><label for="wcu-input-password-confirm"><?php
echo esc_html__( 'Confirm Password', 'woo-coupon-usage' ) ;
?>:*</label>
<input type="password" id="wcu-input-password-confirm" name="wcu-input-password-confirm" class="input-text form-control" value="" style="max-width: 300px; display: inline-block;" required>
</p>
<?php
}
?>
<div style="clear: both;"></div>
<?php
}
?>
<!-- Preferred Code -->
<?php
if ( !$auto_coupon ) {
?>
<p class="wcu-register-field-col"><label for="wcu-input-coupon"><?php
echo esc_html__( 'Preferred Coupon Code', 'woo-coupon-usage' ) ;
?>:*</label>
<input type="text" id="wcu-input-coupon" name="wcu-input-coupon" class="input-text form-control" value="" minlength="3" style="max-width: 300px;" required>
</p>
<?php
}
?>
<?php
?>
<!-- Terms -->
<?php
if ( $wcusage_field_registration_enable_terms ) {
?>
<div class="wcu-reg-terms">
<span style="float: left; margin-top: 1px; margin-right: 7px;"><input type="checkbox" name="reg-checkbox" value="check" id="agree" required></span>
<span style="line-height: 1.5em !important;"><?php
echo html_entity_decode( $wcusage_field_registration_terms_message ) ;
?></span>
</div>
<?php
}
?>
<!-- Recaptcha -->
<?php
if ( $enable_captcha == "1" && !empty($wcusage_registration_recaptcha_key) && $wcusage_registration_recaptcha_key != "" ) {
?>
<p>
<div class="captcha_wrapper">
<div class="g-recaptcha" data-sitekey="<?php
echo esc_attr( $wcusage_registration_recaptcha_key ) ;
?>"></div>
</div>
</p>
<?php
}
?>
<!-- Turnstile -->
<?php
if ( $enable_captcha == "2" && !empty($wcusage_registration_turnstile_key) && $wcusage_registration_turnstile_key != "" ) {
?>
<p>
<div class="captcha_wrapper">
<div class="cf-turnstile" data-sitekey="<?php
echo esc_attr( $wcusage_registration_turnstile_key ) ;
?>"></div>
</div>
</p>
<?php
}
?>
<div style="clear: both;"></div>
<?php
$submit_button_text = wcusage_get_setting_value( 'wcusage_field_registration_submit_button_text', '' );
if ( !$submit_button_text ) {
$submit_button_text = esc_html__( 'Submit Application', 'woo-coupon-usage' );
}
?>
<?php
wp_nonce_field( 'wcusage_verify_submit_registration_form1', 'wcusage_submit_registration_form1' );
?>
<?php
wp_nonce_field( 'wcusage_verify_submit_registration_form2', 'wcusage_submit_registration_form2' );
?>
<p><input type="submit" class="woocommerce-button button" id="wcu-register-button" name="submitaffiliateapplication" value="<?php
echo esc_attr( $submit_button_text ) ;
?>"></p>
</form>
</div>
<?php
} else {
$coupon_shortcode_page = wcusage_get_coupon_shortcode_page( '0' );
?>
<p><?php
echo esc_html__( 'You are already registered as an affiliate.', 'woo-coupon-usage' ) ;
?></p>
<p style="font-weight: bold;">
<a href="<?php
echo esc_url( $coupon_shortcode_page ) ;
?>" style="text-decoration: none;">
<button class="wcu-save-settings-button woocommerce-Button button"><?php
echo esc_html__( 'View affiliate dashboard', 'woo-coupon-usage' ) ;
?> ></button>
</a>
</p>
<?php
}
?>
<?php
} else {
if ( !isset( $_POST['submitaffiliateapplication'] ) ) {
?>
<p><?php
echo esc_html__( 'You already have a pending affiliate application.', 'woo-coupon-usage' ) ;
?></p>
<p><?php
echo esc_html__( 'We are reviewing your application and will be in touch soon!', 'woo-coupon-usage' ) ;
?></p>
<?php
}
}
?>
</div>
<br/>
<?php
} else {
?>
<?php
// Get Login Form
woocommerce_output_all_notices();
woocommerce_login_form();
?>
<?php
}
?>
<?php
} else {
echo "<p>" . esc_html__( 'Sorry, you are not currently allowed to apply as an affiliate.', 'woo-coupon-usage' ) . "</p>" ;
}
$thecontent = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
return $thecontent;
}
Code file location:
woo-coupon-usage/woo-coupon-usage/inc/registration/registration-form.php
Conclusion
Now that you’ve learned how to embed the Woo Coupon Usage Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply