| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template: Wc Coupons field. |
| 4 |
* |
| 5 |
* @var array<string, mixed> $settings Field configuration. |
| 6 |
* @var mixed $value Current saved value. |
| 7 |
* @var string $module_id Module ID. |
| 8 |
* |
| 9 |
* @package Merchant |
| 10 |
* @since 2.2.5 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
$coupons = get_posts( array( |
| 18 |
'posts_per_page' => - 1, |
| 19 |
'orderby' => 'title', |
| 20 |
'order' => 'asc', |
| 21 |
'post_type' => 'shop_coupon', |
| 22 |
'post_status' => 'publish', |
| 23 |
) ); |
| 24 |
|
| 25 |
if ( $coupons ) { |
| 26 |
?> |
| 27 |
<div class="merchant-wc-coupon-selector merchant-<?php echo esc_attr( $settings['id'] ) ?>"> |
| 28 |
<?php |
| 29 |
echo '<select name="merchant[' . esc_attr( $settings['id'] ) . ']">'; |
| 30 |
echo '<option value="">' . esc_html__( 'Select a coupon', 'merchant' ) . '</option>'; |
| 31 |
|
| 32 |
foreach ( $coupons as $coupon ) { |
| 33 |
$coupon_code = strtolower( $coupon->post_title ); |
| 34 |
echo '<option value="' . esc_attr( $coupon_code ) . '"' . selected( esc_attr( $coupon_code ), $value, false ) . '>'; |
| 35 |
echo esc_html( $coupon_code ); |
| 36 |
echo '</option>'; |
| 37 |
} |
| 38 |
|
| 39 |
echo '</select>'; |
| 40 |
echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=shop_coupon' ) ) . '" target="_blank" style="margin-left: 10px;">' . esc_html__( 'Manage coupons', 'merchant' ) . '</a>'; |
| 41 |
?> |
| 42 |
</div> |
| 43 |
<?php |
| 44 |
} else { |
| 45 |
echo '<div style="color: red;">'; |
| 46 |
echo wp_kses_post( |
| 47 |
sprintf( |
| 48 |
/* Translators: 1. Coupon admin url 2. Link target attribute value */ |
| 49 |
__( 'No coupons found! <a href="%1$s" target="%2$s">Create a new coupon</a>', 'merchant' ), |
| 50 |
admin_url( 'post-new.php?post_type=shop_coupon' ), |
| 51 |
'_blank' |
| 52 |
) |
| 53 |
); |
| 54 |
echo '</div>'; |
| 55 |
echo '<input type="hidden" name="merchant[' . esc_attr( $settings['id'] ) . ']" value="" />'; |
| 56 |
} |
| 57 |
|