| 1 |
<?php namespace TierPricingTable\Addons\PluginsRecommendations; |
| 2 |
|
| 3 |
use TierPricingTable\Admin\Tips\Tip; |
| 4 |
|
| 5 |
/** |
| 6 |
* A simple, dismissible tip for U2Code Product Addons in the product's Tiered Pricing tab |
| 7 |
* (Additional Options): one line of copy and two buttons — one-click install of the free |
| 8 |
* plugin and a link to the plugin site. Nothing renders once the plugin is active or the |
| 9 |
* tip was hidden (store-wide, via the standard Tips mechanism). |
| 10 |
*/ |
| 11 |
class U2CodeProductAddonsPlugin extends Tip { |
| 12 |
|
| 13 |
const WPORG_SLUG = 'u2code-product-addons-for-woocommerce'; |
| 14 |
|
| 15 |
public function getSlug(): string { |
| 16 |
return 'u2code_product_addons_tip'; |
| 17 |
} |
| 18 |
|
| 19 |
public static function isAddonsPluginActive(): bool { |
| 20 |
// Free build (SimpleProductAddons) or premium build (U2Code\ProductAddons) |
| 21 |
return class_exists( '\\SimpleProductAddons\\Plugin' ) || class_exists( '\\U2Code\\ProductAddons\\Plugin' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function __construct() { |
| 25 |
parent::__construct(); |
| 26 |
|
| 27 |
// Resolve this tip for the standard dismiss AJAX without touching TipsManager's list. |
| 28 |
add_filter( 'tiered_pricing_table/admin/tips/get_tip_by_slug', function ( $tip, $slug ) { |
| 29 |
return $slug === $this->getSlug() ? $this : $tip; |
| 30 |
}, 10, 2 ); |
| 31 |
|
| 32 |
add_action( 'init', function () { |
| 33 |
|
| 34 |
// The plugin is already there (free or premium build) — nothing to recommend. |
| 35 |
if ( self::isAddonsPluginActive() ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
add_action( 'tiered_pricing_table/admin/advance_product_options', array( $this, 'render' ) ); |
| 40 |
} ); |
| 41 |
} |
| 42 |
|
| 43 |
public function render() { |
| 44 |
|
| 45 |
if ( $this->isSeen() ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
// Belt and braces: never show the tip while the plugin is active, regardless of hook timing. |
| 50 |
if ( self::isAddonsPluginActive() ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
if ( current_user_can( 'install_plugins' ) ) { |
| 55 |
$installURL = wp_nonce_url( |
| 56 |
self_admin_url( 'update.php?action=install-plugin&plugin=' . self::WPORG_SLUG ), |
| 57 |
'install-plugin_' . self::WPORG_SLUG |
| 58 |
); |
| 59 |
$installLabel = __( 'Install now — free', 'tier-pricing-table' ); |
| 60 |
} else { |
| 61 |
$installURL = 'https://wordpress.org/plugins/' . self::WPORG_SLUG . '/'; |
| 62 |
$installLabel = __( 'Free on WordPress.org', 'tier-pricing-table' ); |
| 63 |
} |
| 64 |
?> |
| 65 |
<div class="tiered-pricing-tip" |
| 66 |
style="margin: 12px; padding: 10px; background: #fafafa; border: 1px solid #eeeeee; display: flex; gap: 10px; justify-content: space-between"> |
| 67 |
<div style="display:flex; gap: 10px;"> |
| 68 |
<div style="color: #2272b1; margin: 0 5px;"> |
| 69 |
<span class="dashicons dashicons-plus-alt"></span> |
| 70 |
</div> |
| 71 |
<div> |
| 72 |
<strong> |
| 73 |
<?php esc_html_e( 'Tip', 'tier-pricing-table' ); ?>: |
| 74 |
</strong> |
| 75 |
|
| 76 |
<?php esc_html_e( 'Want to charge for product options — engraving, gift wrap, services?', 'tier-pricing-table' ); ?> |
| 77 |
|
| 78 |
<div style="margin-top: 5px; color: #50575e;"> |
| 79 |
<?php esc_html_e( 'U2Code Product Addons pairs with tiered pricing: option prices follow the tier price and appear in the live totals. By the makers of this plugin.', 'tier-pricing-table' ); ?> |
| 80 |
</div> |
| 81 |
|
| 82 |
<div style="margin-top: 10px; display: flex; gap: 8px;"> |
| 83 |
<a class="button button-primary" href="<?php echo esc_url( $installURL ); ?>"> |
| 84 |
<?php echo esc_html( $installLabel ); ?> |
| 85 |
</a> |
| 86 |
<a class="button" target="_blank" rel="noopener" |
| 87 |
href="https://product-addons.com/?utm_source=tiered-pricing-table&utm_medium=plugin&utm_campaign=product-tab-tip"> |
| 88 |
<?php esc_html_e( 'Learn more', 'tier-pricing-table' ); ?> |
| 89 |
</a> |
| 90 |
</div> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
|
| 94 |
<div style="white-space: nowrap;"> |
| 95 |
<a role="button" href="<?php echo esc_attr( $this->getMarkAsSeenURL() ); ?>" |
| 96 |
class="tiered-pricing-tip-close-button"> |
| 97 |
× <?php esc_html_e( 'Hide this tip', 'tier-pricing-table' ); ?> |
| 98 |
</a> |
| 99 |
</div> |
| 100 |
</div> |
| 101 |
<?php |
| 102 |
} |
| 103 |
} |
| 104 |
|