PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.1
Tiered Pricing Table for WooCommerce v7.1.1
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Integrations / Plugins / RankMath / RankMath.php

RankMath.php in Tiered Pricing Table for WooCommerce 7.1.1, at src/Integrations/Plugins/RankMath/RankMath.php

102 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TierPricingTable\Integrations\Plugins\RankMath;
4
5 use RankMath\Helpers\Param;
6 use TierPricingTable\Integrations\Plugins\PluginIntegrationAbstract;
7 use TierPricingTable\Managers\FormatPriceManager;
8 use TierPricingTable\PriceManager;
9 use TierPricingTable\TierPricingTablePlugin;
10 use WC_Product;
11 class RankMath extends PluginIntegrationAbstract {
12 protected $product = null;
13
14 public function getTitle() : string {
15 return 'Rank Math SEO';
16 }
17
18 public function getDescription() : string {
19 return __( 'Add tiered pricing data to the product schema and introduce <b>%lowest_price%</b> and <b>%price_range%</b> variables for SEO.', 'tier-pricing-table' );
20 }
21
22 public function getSlug() : string {
23 return 'rank-math';
24 }
25
26 public function run() {
27 add_action( 'plugins_loaded', function () {
28 if ( !class_exists( 'RankMath\\Helpers\\Param' ) || !function_exists( 'rank_math_register_var_replacement' ) ) {
29 return;
30 }
31 add_filter( 'tiered_pricing_table/settings/sections', function ( $sections ) {
32 $sections[] = new Settings();
33 return $sections;
34 } );
35 } );
36 }
37
38 protected function getProductJSONldOffers() : array {
39 }
40
41 public function getIntegrationCategory() : string {
42 return 'seo';
43 }
44
45 public function getIconURL() : ?string {
46 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/rank-math-icon.svg' );
47 }
48
49 public function getPriceRange() : ?string {
50 $product = $this->get_product();
51 if ( !$product ) {
52 return '';
53 }
54 $price = FormatPriceManager::getFormattedPrice( $product, array(
55 'for_display' => true,
56 'with_suffix' => false,
57 'with_default_price' => true,
58 'with_lowest_prefix' => false,
59 'html' => true,
60 'display_type' => 'range',
61 ) );
62 return ( $price ? $price : '' );
63 }
64
65 public function getLowestPrice() : ?string {
66 $product = $this->get_product();
67 if ( !$product ) {
68 return '';
69 }
70 $price = FormatPriceManager::getFormattedPrice( $product, array(
71 'for_display' => true,
72 'with_suffix' => false,
73 'with_default_price' => true,
74 'with_lowest_prefix' => false,
75 'html' => true,
76 'display_type' => 'lowest_price',
77 ) );
78 return ( $price ? $price : '' );
79 }
80
81 public function get_product() {
82 if ( !is_null( $this->product ) ) {
83 return $this->product;
84 }
85 if ( !class_exists( 'RankMath\\Helpers\\Param' ) ) {
86 return null;
87 }
88 $product_id = Param::get( 'post', get_queried_object_id(), FILTER_VALIDATE_INT );
89 $this->product = ( !function_exists( 'wc_get_product' ) || !$product_id || !is_admin() && !is_singular( 'product' ) ? null : wc_get_product( $product_id ) );
90 return $this->product;
91 }
92
93 public function isVariablesEnabled() : bool {
94 return $this->getContainer()->getSettings()->get( 'rank_math_enable_variables', 'yes' ) === 'yes';
95 }
96
97 public function isEnhancedSchemaEnabled() : bool {
98 return $this->getContainer()->getSettings()->get( 'rank_math_enhance_schema', 'no' ) === 'yes';
99 }
100
101 }
102