| 1 |
<?php |
| 2 |
|
| 3 |
namespace TierPricingTable\Integrations\Plugins\SEOPress; |
| 4 |
|
| 5 |
use TierPricingTable\Integrations\Plugins\PluginIntegrationAbstract; |
| 6 |
use TierPricingTable\Managers\FormatPriceManager; |
| 7 |
use TierPricingTable\PriceManager; |
| 8 |
use TierPricingTable\TierPricingTablePlugin; |
| 9 |
use WC_Product; |
| 10 |
class SEOPress extends PluginIntegrationAbstract { |
| 11 |
protected $product = null; |
| 12 |
|
| 13 |
public function getTitle() : string { |
| 14 |
return 'SEOPress'; |
| 15 |
} |
| 16 |
|
| 17 |
public function getDescription() : string { |
| 18 |
return __( 'Adds <b>%%lowest_price%%</b> and <b>%%price_range%%</b> variables to display the lowest and price range of products with tiered pricing.', 'tier-pricing-table' ); |
| 19 |
} |
| 20 |
|
| 21 |
public function getSlug() : string { |
| 22 |
return 'seopress'; |
| 23 |
} |
| 24 |
|
| 25 |
public function run() { |
| 26 |
add_action( 'plugins_loaded', function () { |
| 27 |
if ( !function_exists( 'seopress_init' ) ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
add_filter( 'tiered_pricing_table/settings/sections', function ( $sections ) { |
| 31 |
// Ensure you create a corresponding Settings class for SEOPress in this namespace |
| 32 |
$sections[] = new Settings(); |
| 33 |
return $sections; |
| 34 |
} ); |
| 35 |
} ); |
| 36 |
} |
| 37 |
|
| 38 |
public function getIntegrationCategory() : string { |
| 39 |
return 'seo'; |
| 40 |
} |
| 41 |
|
| 42 |
public function getPrice( $type ) : ?string { |
| 43 |
$product = $this->get_product(); |
| 44 |
if ( !$product ) { |
| 45 |
return ''; |
| 46 |
} |
| 47 |
return FormatPriceManager::getFormattedPrice( $product, array( |
| 48 |
'for_display' => true, |
| 49 |
'with_suffix' => false, |
| 50 |
'with_default_price' => true, |
| 51 |
'with_lowest_prefix' => false, |
| 52 |
'html' => false, |
| 53 |
'display_type' => $type, |
| 54 |
) ); |
| 55 |
} |
| 56 |
|
| 57 |
public function getIconURL() : ?string { |
| 58 |
// Make sure to add a seopress-icon.png/gif to your assets |
| 59 |
return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/seopress-icon.gif' ); |
| 60 |
} |
| 61 |
|
| 62 |
public function get_product() { |
| 63 |
if ( !is_null( $this->product ) ) { |
| 64 |
return $this->product; |
| 65 |
} |
| 66 |
$product_id = get_queried_object_id(); |
| 67 |
$this->product = ( !function_exists( 'wc_get_product' ) || !$product_id || !is_admin() && !is_singular( 'product' ) ? null : wc_get_product( $product_id ) ); |
| 68 |
return $this->product; |
| 69 |
} |
| 70 |
|
| 71 |
public function isVariablesEnabled() : bool { |
| 72 |
return $this->getContainer()->getSettings()->get( 'seopress_enable_variables', 'yes' ) === 'yes'; |
| 73 |
} |
| 74 |
|
| 75 |
public function isEnhancedSchemaEnabled() : bool { |
| 76 |
return $this->getContainer()->getSettings()->get( 'seopress_enhance_schema', 'no' ) === 'yes'; |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|