Woocommerce_Catalog_Mode

Plugin Name: Woocommerce Catalog Plugin URI: https://wordpress.org/plugins/ Description: Switch to Catalog mode with one click.

Defined (1)

The class is defined in the following location(s).

/woocommerce_catalogue.php  
  1. class Woocommerce_Catalog_Mode { 
  2.  
  3. public $version = '20141106'; // Latest version release date Year-Month-Day 
  4.  
  5. public $url = ''; // URL of plugin installation 
  6.  
  7. public $path = ''; // Path of plugin installation 
  8.  
  9. public $file = ''; // Path of this file 
  10.  
  11. public $settings; // Settings object 
  12.  
  13.  
  14. //options 
  15. public $catalog_mode; 
  16. public $remove_add_to_cart_button; 
  17. public $user_groups; 
  18. public $woo_categories; 
  19. public $add_custom_button; 
  20. public $custom_button_type; 
  21. public $remove_price; 
  22. public $load_more_button_text; 
  23. public $custom_button_link; 
  24.  
  25. public $catalog_on=false; 
  26.  
  27.  
  28.  
  29.  
  30.  
  31. function __construct() { 
  32.  
  33. $this->file = __file__; 
  34.  
  35. $this->path = dirname($this->file) . '/'; 
  36.  
  37. $this->url = WP_PLUGIN_URL . '/' . plugin_basename(dirname(__file__)) . '/'; 
  38.  
  39. require_once ($this->path . 'include/php/settings.php'); 
  40.  
  41. $this->settings = new Woo_Catalog_Settings($this->file); 
  42.  
  43. //assign options 
  44. $this->catalog_mode=get_option('woo_Catalog_catalog_mode'); 
  45. $this->remove_add_to_cart_button=get_option('woo_Catalog_remove_add_to_cart_button'); 
  46. $this->remove_price=get_option('woo_Catalog_remove_price'); 
  47. $this->add_custom_button=get_option('woo_Catalog_add_custom_button'); 
  48. $this->custom_button_type =get_option('woo_Catalog_custom_button_type'); 
  49. $this->custom_button_link =get_option('woo_Catalog_custom_button_link'); 
  50. $this->user_groups =get_option('woo_Catalog_catalog_groups'); 
  51. $this->woo_categories =get_option('woo_Catalog_categories'); 
  52.  
  53.  
  54. if ($this->catalog_mode=="on") { 
  55.  
  56. add_action('plugins_loaded', array($this, 'configCatalog')); 
  57.  
  58.  
  59. add_action('wp_enqueue_scripts', array($this, 'register_frontend_assets')); 
  60.  
  61. add_action('wp_enqueue_scripts', array($this, 'load_frontend_assets')); 
  62.  
  63.  
  64. add_action('plugins_loaded', array($this, 'configLang')); 
  65.  
  66.  
  67.  
  68. public function woo_catalogue_apply() { 
  69. //check for user groups 
  70. if($this->catalog_on) { 
  71.  
  72. if ($this->remove_add_to_cart_button=="on") { 
  73. add_action('init', array($this, 'remove_add_to_cart_button')); 
  74. if ($this->remove_price=="on") { 
  75. add_action('init', array($this, 'remove_price')); 
  76.  
  77.  
  78.  
  79.  
  80. public function register_frontend_assets() { 
  81.  
  82. // Add frontend assets in footer 
  83.  
  84. wp_register_style('woocommerce-catalog-frontend-custom-style', $this->url . 'include/css/style.php'); 
  85.  
  86.  
  87.  
  88.  
  89.  
  90. public function load_frontend_assets() { 
  91.  
  92. //load all scripts 
  93. wp_enqueue_style( 'woocommerce-catalog-frontend-custom-style' ); 
  94.  
  95.  
  96.  
  97. public function remove_add_to_cart_button() { 
  98.  
  99.  
  100. if ($this->add_custom_button=="on") { 
  101. add_filter('woocommerce_loop_add_to_cart_link', array($this, 'custom_button'), 10); 
  102. add_action( 'woocommerce_after_shop_loop_item', array($this, 'set_up_template_add_to_cart'), 1 );  
  103. }else{ 
  104. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); 
  105. add_action( 'woocommerce_after_shop_loop_item', array($this, 'set_up_template_add_to_cart'), 1 );  
  106.  
  107. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); 
  108. add_action( 'woocommerce_single_product_summary', array($this, 'set_up_template_add_to_cart'), 1 ); 
  109.  
  110.  
  111. public function custom_button() { 
  112. $this->load_more_button_text= get_option('woo_Catalog_button_text')==""?__( 'More', 'woocommerce-catalog' ):get_option('woo_Catalog_button_text'); 
  113.  
  114. if ($this->custom_button_type=="custom_button_type_read_more") { 
  115. global $product; 
  116. echo ' <a id="woocommerce-catalog_custom_button" href="' . esc_url( $product->get_permalink( $product->id ) ) . '" class="single_add_to_cart_button button alt">'.$this->load_more_button_text.'</a> 
  117. </a>'; 
  118. }else{ 
  119. echo ' <a id="woocommerce-catalog_custom_button" href="' . $this->custom_button_link . '" class="single_add_to_cart_button button alt">'.$this->load_more_button_text.'</a> 
  120. </a>'; 
  121.  
  122.  
  123. public function set_up_template_add_to_cart() { 
  124. if($this->isCategoriesExludedFromCatalog()) {//excluded categories bring back add to cart 
  125. remove_filter('woocommerce_loop_add_to_cart_link', array($this, 'custom_button'), 10); 
  126. add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); 
  127. add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); 
  128.  
  129. }else{ 
  130. //in catalog 
  131. if ($this->add_custom_button!="on") { 
  132. remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); 
  133. }else{ 
  134. add_filter('woocommerce_loop_add_to_cart_link', array($this, 'custom_button'), 10); 
  135.  
  136. public function remove_price() { 
  137.  
  138.  
  139. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); 
  140. add_action( 'woocommerce_single_product_summary', array($this, 'set_up_template_price'), 5 ); 
  141. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );  
  142. add_action( 'woocommerce_after_shop_loop_item_title', array($this, 'set_up_template_price'), 1 ); 
  143.  
  144. public function set_up_template_price() { 
  145.  
  146. if($this->isCategoriesExludedFromCatalog()) { 
  147. add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); 
  148. add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); 
  149. }else{ 
  150. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); 
  151. remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. public function isCategoriesExludedFromCatalog() { 
  158.  
  159. global $product; 
  160. $terms = get_the_terms( $product->id, 'product_cat' ); 
  161. if(!in_array("all", $this->woo_categories)) { 
  162. if($terms) { 
  163. $cat_ids=array_keys($terms); 
  164. foreach ($cat_ids as $c_id) { 
  165. if(!in_array($c_id, $this->woo_categories)) { 
  166. return true; 
  167.  
  168. return false; 
  169.  
  170.  
  171.  
  172. public function version() { 
  173.  
  174. return $this->version; 
  175.  
  176.  
  177. public function configLang() { 
  178. $lang_dir = basename(dirname(__FILE__)). '/languages'; 
  179. load_plugin_textdomain( 'woocommerce-catalog', false, $lang_dir ); 
  180.  
  181. public function configCatalog() { 
  182.  
  183. if($this->user_groups=="registered_users") { 
  184. if ( is_user_logged_in() ) { 
  185. $this->catalog_on=true; 
  186. if($this->user_groups=="non_registered_users") { 
  187. if ( !is_user_logged_in() ) { 
  188. $this->catalog_on=true; 
  189.  
  190. if($this->user_groups=="all") { 
  191. $this->catalog_on=true; 
  192.  
  193.  
  194. add_action('init', array($this, 'woo_catalogue_apply'), 3);  
  195.  
  196.