| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Helpers; |
| 4 |
|
| 5 |
/** |
| 6 |
* Represents helper methods for WooCommerce. |
| 7 |
*/ |
| 8 |
class Woocommerce_Helper { |
| 9 |
|
| 10 |
/** |
| 11 |
* Checks if WooCommerce is active. |
| 12 |
* |
| 13 |
* @return bool Is WooCommerce active. |
| 14 |
*/ |
| 15 |
public function is_active() { |
| 16 |
return \class_exists( 'WooCommerce' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Returns the id of the set WooCommerce shop page. |
| 21 |
* |
| 22 |
* @return int The ID of the set page. |
| 23 |
*/ |
| 24 |
public function get_shop_page_id() { |
| 25 |
if ( ! \function_exists( 'wc_get_page_id' ) ) { |
| 26 |
return -1; |
| 27 |
} |
| 28 |
|
| 29 |
return \wc_get_page_id( 'shop' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Checks if the current page is a WooCommerce shop page. |
| 34 |
* |
| 35 |
* @return bool True when the page is a shop page. |
| 36 |
*/ |
| 37 |
public function is_shop_page() { |
| 38 |
if ( ! \function_exists( 'is_shop' ) ) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
if ( ! \is_shop() ) { |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
if ( \is_search() ) { |
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
return true; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Checks if the current page is a WooCommerce shop page. |
| 55 |
* |
| 56 |
* @return bool True when the page is a shop page. |
| 57 |
*/ |
| 58 |
public function current_post_is_terms_and_conditions_page() { |
| 59 |
if ( ! \function_exists( 'wc_terms_and_conditions_page_id' ) ) { |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
global $post; |
| 64 |
|
| 65 |
if ( ! isset( $post->ID ) ) { |
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
return \intval( $post->ID ) === \intval( \wc_terms_and_conditions_page_id() ); |
| 70 |
} |
| 71 |
} |
| 72 |
|