| 1 |
<?php defined( 'ABSPATH' ) || die; |
| 2 |
|
| 3 |
use TierPricingTable\Addons\RoleBasedPricing\ProductManager; |
| 4 |
use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPricingRule; |
| 5 |
use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPriceManager; |
| 6 |
use TierPricingTable\Core\ServiceContainer; |
| 7 |
|
| 8 |
/** |
| 9 |
* Available variables |
| 10 |
* |
| 11 |
* @var int $product_id |
| 12 |
* @var int $loop |
| 13 |
*/ |
| 14 |
|
| 15 |
$product = wc_get_product( $product_id ); |
| 16 |
|
| 17 |
if ( ! $product ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
$loop = ! is_null( $loop ) ? $loop : null; |
| 22 |
|
| 23 |
$fileManager = ServiceContainer::getInstance()->getFileManager(); |
| 24 |
|
| 25 |
?> |
| 26 |
|
| 27 |
<div class="form-field tpt-role-based-block" id="tpt-role-based-block-<?php echo esc_attr( $product_id ); ?>" |
| 28 |
data-product-type="<?php echo esc_attr( $product->get_type() ); ?>" |
| 29 |
data-add-action="<?php echo esc_attr( ProductManager::GET_ROLE_ROW_HTML__ACTION ); ?>" |
| 30 |
data-add-action-nonce="<?php echo esc_attr( wp_create_nonce( ProductManager::GET_ROLE_ROW_HTML__ACTION ) ); ?>" |
| 31 |
data-product-id="<?php echo esc_attr( $product_id ); ?>" |
| 32 |
data-loop="<?php echo esc_attr( $loop ); ?>"> |
| 33 |
<label class="tpt-role-based-block__name" style="line-height: normal"><?php esc_attr_e( 'Role-based pricing', 'tier-pricing-table' ); ?></label> |
| 34 |
<div class="tpt-role-based-block__content"> |
| 35 |
<div class="tpt-role-based-roles"> |
| 36 |
<?php |
| 37 |
|
| 38 |
$presentRoles = array(); |
| 39 |
|
| 40 |
foreach ( wp_roles()->roles as $WPRole => $role_data ) { |
| 41 |
|
| 42 |
if ( RoleBasedPriceManager::roleHasRules( $WPRole, $product_id, 'edit' ) ) { |
| 43 |
|
| 44 |
$roleBasedRule = RoleBasedPricingRule::build( $product_id, $WPRole ); |
| 45 |
|
| 46 |
$fileManager->includeTemplate( 'addons/role-based-pricing/role.php', array( |
| 47 |
'pricing_rule' => $roleBasedRule, |
| 48 |
'role' => $WPRole, |
| 49 |
'product_id' => $product_id, |
| 50 |
'product' => $product, |
| 51 |
'loop' => $loop, |
| 52 |
) ); |
| 53 |
|
| 54 |
$presentRoles[] = $WPRole; |
| 55 |
} |
| 56 |
} |
| 57 |
?> |
| 58 |
</div> |
| 59 |
|
| 60 |
<div class="tpt-role-based-no-roles" |
| 61 |
style="<?php echo esc_attr( ! empty( $presentRoles ) ? 'display: none;' : '' ); ?>"> |
| 62 |
<span> |
| 63 |
<?php |
| 64 |
esc_attr_e( 'Set up specific pricing and rules for different user roles.', |
| 65 |
'tier-pricing-table' ); |
| 66 |
?> |
| 67 |
</span> |
| 68 |
<p class="description" style="display: block; margin: 0"> |
| 69 |
<?php |
| 70 |
$settingsLink = add_query_arg( array( |
| 71 |
'section' => 'advanced', |
| 72 |
), ServiceContainer::getInstance()->getSettings()->getLink() ); |
| 73 |
|
| 74 |
$settingsLink = sprintf( '<a target="_blank" href="%s">%s</a>', esc_url( $settingsLink ), |
| 75 |
esc_html__( 'settings', 'tier-pricing-table' ) ); |
| 76 |
// translators: %s: settings link |
| 77 |
echo wp_kses_post( sprintf( __( 'You can disable this feature in the %s if you don\'t need role-based pricing.', |
| 78 |
'tier-pricing-table' ), $settingsLink ) ); |
| 79 |
|
| 80 |
?> |
| 81 |
|
| 82 |
</p> |
| 83 |
</div> |
| 84 |
|
| 85 |
<div class="tpt-role-based-adding-form"> |
| 86 |
<select class="tpt-role-based-adding-form__role-selector"> |
| 87 |
<?php foreach ( wp_roles()->roles as $key => $WPRole ) : ?> |
| 88 |
<?php if ( ! in_array( $key, $presentRoles ) ) : ?> |
| 89 |
<option value="<?php echo esc_attr( $key ); ?>"> |
| 90 |
<?php echo esc_attr( $WPRole['name'] ); ?> |
| 91 |
</option> |
| 92 |
<?php endif; ?> |
| 93 |
<?php endforeach; ?> |
| 94 |
</select> |
| 95 |
|
| 96 |
<button class="button tpt-role-based-adding-form__add-button"> |
| 97 |
<?php |
| 98 |
esc_attr_e( 'Add role pricing', 'tier-pricing-table' ); |
| 99 |
?> |
| 100 |
</button> |
| 101 |
<div class="clear"></div> |
| 102 |
</div> |
| 103 |
|
| 104 |
<?php $rolesToDeleteName = ! is_null( $loop ) ? "tiered_price_rules_roles_to_delete_variation[$loop][]" : 'tiered_price_rules_roles_to_delete[]'; ?> |
| 105 |
|
| 106 |
<select name="<?php echo esc_attr( $rolesToDeleteName ); ?>" class="tiered_price_rules_roles_to_delete" multiple |
| 107 |
style="display:none;"> |
| 108 |
<?php foreach ( wp_roles()->roles as $key => $WPRole ) : ?> |
| 109 |
<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $WPRole['name'] ); ?></option> |
| 110 |
<?php endforeach; ?> |
| 111 |
</select> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
|