PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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
← All changes | src/Integrations/Plugins/Yoast/Yoast.php +37 -28 6.4.0 → 8.0.2 View file →
@@ -1,16 +1,11 @@
1 1 <?php
2 2
3 3 namespace TierPricingTable\Integrations\Plugins\Yoast;
4 4
5 -use TierPricingTable\Integrations\Plugins\PluginIntegrationAbstract;
6 -use TierPricingTable\Managers\FormatPriceManager;
7 -use TierPricingTable\PriceManager;
8 -use TierPricingTable\TierPricingTablePlugin;
5 +use TierPricingTable\Integrations\Plugins\SeoIntegrationAbstract;
9 6 use WC_Product;
10 -class Yoast extends PluginIntegrationAbstract {
11 - protected $product = null;
12 -
7 +class Yoast extends SeoIntegrationAbstract {
13 8 public function getTitle() : string {
14 9 return 'Yoast SEO';
15 10 }
16 11
@@ -21,8 +16,16 @@
21 16 public function getSlug() : string {
22 17 return 'yoast-seo';
23 18 }
24 19
20 + protected function getSettingsPrefix() : string {
21 + return 'yoast';
22 + }
23 +
24 + protected function getSchemaFilterSlug() : string {
25 + return 'yoast_seo';
26 + }
27 +
25 28 public function run() {
26 29 add_action( 'plugins_loaded', function () {
27 30 if ( !class_exists( 'WPSEO_Options' ) ) {
28 31 return;
@@ -31,32 +34,38 @@
31 34 $sections[] = new Settings();
32 35 return $sections;
33 36 } );
34 37 } );
38 + return;
39 + add_filter(
40 + 'wpseo_replacements',
41 + function ( $replacements ) {
42 + if ( !$this->isVariablesEnabled() ) {
43 + return $replacements;
44 + }
45 + if ( !$this->get_product() ) {
46 + return $replacements;
47 + }
48 + $replacements['%%lowest_price%%'] = $this->getFormattedProductPrice( 'lowest_price' );
49 + $replacements['%%price_range%%'] = $this->getFormattedProductPrice( 'range' );
50 + return $replacements;
51 + },
52 + 10,
53 + 2
54 + );
55 + add_filter( 'wpseo_schema_product', function ( $data ) {
56 + if ( !is_product() || !is_array( $data ) ) {
57 + return $data;
58 + }
59 + global $product;
60 + if ( !$this->isEnhancedSchemaEnabled() || !$product instanceof WC_Product ) {
61 + return $data;
62 + }
63 + return $this->enhanceProductSchema( $data, $product );
64 + } );
35 65 }
36 66
37 - public function getIntegrationCategory() : string {
38 - return 'seo';
39 - }
40 -
41 67 public function getIconURL() : ?string {
42 68 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/yoast-icon.gif' );
43 - }
44 -
45 - public function get_product() {
46 - if ( !is_null( $this->product ) ) {
47 - return $this->product;
48 - }
49 - $product_id = get_queried_object_id();
50 - $this->product = ( !function_exists( 'wc_get_product' ) || !$product_id || !is_admin() && !is_singular( 'product' ) ? null : wc_get_product( $product_id ) );
51 - return $this->product;
52 - }
53 -
54 - public function isVariablesEnabled() : bool {
55 - return $this->getContainer()->getSettings()->get( 'yoast_enable_variables', 'yes' ) === 'yes';
56 - }
57 -
58 - public function isEnhancedSchemaEnabled() : bool {
59 - return $this->getContainer()->getSettings()->get( 'yoast_enhance_schema', 'no' ) === 'yes';
60 69 }
61 70
62 71 }