暫無描述

main.php 107KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  1. <?php
  2. define( "BeRocket_product_brand_domain", 'brands-for-woocommerce');
  3. define( "product_brand_TEMPLATE_PATH", plugin_dir_path( __FILE__ ) . "templates/" );
  4. load_plugin_textdomain('brands-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
  5. require_once(plugin_dir_path( __FILE__ ).'berocket/framework.php');
  6. foreach ( glob( __DIR__ . "/includes/*.php" ) as $filename ) {
  7. include_once($filename);
  8. }
  9. class BeRocket_product_brand extends BeRocket_Framework {
  10. public static $settings_name = 'br-product_brand-options', $taxonomy_name = 'berocket_brand';
  11. protected static $instance;
  12. protected $plugin_version_capability = 15;
  13. public $info, $defaults, $values;
  14. private $attributes;
  15. private $cache_key = 'br_brands_cache_', $cache_time = 60*60*24, $cache_list = 'br_brands_cache_list';
  16. function __construct () {
  17. global $berocket_unique_value;
  18. $berocket_unique_value = 1;
  19. $this->info = array(
  20. 'id' => 19,
  21. 'version' => BeRocket_product_brand_version,
  22. 'plugin' => '',
  23. 'slug' => '',
  24. 'key' => '',
  25. 'name' => '',
  26. 'plugin_name' => 'product_brand',
  27. 'full_name' => 'Brands for WooCommerce',
  28. 'norm_name' => 'Brands',
  29. 'price' => '24',
  30. 'domain' => 'brands-for-woocommerce',
  31. 'templates' => product_brand_TEMPLATE_PATH,
  32. 'plugin_file' => BeRocket_product_brand_file,
  33. 'plugin_dir' => __DIR__,
  34. );
  35. $this->defaults = array(
  36. 'use_cache' => 1,
  37. 'thumbnail_display' => 1,
  38. 'thumbnail_align' => 'left',
  39. 'thumbnail_fit' => 'cover',
  40. 'thumbnail_height' => '',
  41. 'thumbnail_height_units' => 'px',
  42. 'thumbnail_width' => 10,
  43. 'thumbnail_width_units' => '%',
  44. 'banner_display' => '',
  45. 'banner_align' => 'none',
  46. 'banner_fit' => 'cover',
  47. 'banner_height' => '',
  48. 'banner_height_units' => 'px',
  49. 'banner_width' => 100,
  50. 'banner_width_units' => '%',
  51. 'display_description' => 1,
  52. 'display_link' => 1,
  53. 'link_text' => __( 'Go to the brand website >>', 'brands-for-woocommerce' ),
  54. 'link_open_in_new_tab' => 1,
  55. 'related_products_display' => 1,
  56. 'related_products_columns' => 3,
  57. 'related_products_per_page' => 3,
  58. 'related_products_hide_brands' => 1,
  59. 'related_products_order' => 'asc',
  60. 'related_products_orderby' => 'title',
  61. 'related_products_slider' => 1,
  62. 'slider_autoplay' => 1,
  63. 'slider_autoplay_speed' => 5000,
  64. 'slider_change_speed' => 1000,
  65. 'slider_infinite' => 1,
  66. 'slider_arrows' => 1,
  67. 'slider_slides_scroll' => 1,
  68. 'slider_mode' => 'slide',
  69. 'slider_ease' => 'linear',
  70. 'slider_stop_focus' => 1,
  71. 'slider_dots' => '',
  72. 'slider_dots_color' => '#00CFFF',
  73. 'custom_css' => '',
  74. 'global_font_awesome_disable' => 1,
  75. 'global_fontawesome_version' => '',
  76. 'script' => array(
  77. 'js_page_load' => '',
  78. ),
  79. 'fontawesome_frontend_disable' => '',
  80. 'fontawesome_frontend_version' => '',
  81. );
  82. $this->attributes = array(
  83. 'brand_image_url' => array(
  84. 'type' => 'image',
  85. "label" => __( 'Thumbnail', 'brands-for-woocommerce' ),
  86. 'image_name' => 'br_brand_image',
  87. 'default' => '',
  88. ),
  89. 'brand_banner_url' => array(
  90. 'type' => 'image',
  91. "label" => __( 'Banner', 'brands-for-woocommerce' ),
  92. 'image_name' => 'br_brand_banner',
  93. 'default' => '',
  94. ),
  95. 'br_brand_category' => array(
  96. 'type' => 'category_checklist',
  97. "label" => __( 'Categories', 'brands-for-woocommerce' ),
  98. 'description' => __( 'Product categories', 'brands-for-woocommerce' ),
  99. 'default' => false,
  100. ),
  101. 'br_brand_tooltip' => array(
  102. 'type' => 'text',
  103. "label" => __( 'Tooltip', 'brands-for-woocommerce' ),
  104. 'description' => __( 'Optional message to pop up on hover or on click', 'brands-for-woocommerce' ),
  105. 'default' => '',
  106. ),
  107. 'br_brand_email' => array(
  108. 'type' => 'text',
  109. "label" => __( 'Email', 'brands-for-woocommerce' ),
  110. 'description' => __( 'Email for purchase order', 'brands-for-woocommerce' ),
  111. 'default' => '',
  112. ),
  113. 'br_brand_related' => array(
  114. 'type' => 'products_selector',
  115. "label" => __( 'Related products', 'brands-for-woocommerce' ),
  116. 'description' => __( 'Products that may be related to this brand', 'brands-for-woocommerce' ),
  117. 'default' => '',
  118. ),
  119. 'br_brand_order' => array(
  120. 'type' => 'hidden',
  121. "label" => '',
  122. 'default' => 0,
  123. ),
  124. // 'br_brand_order' => array(
  125. // 'type' => 'number',
  126. // 'attributes' => array(
  127. // 'min' => '0',
  128. // ),
  129. // "label" => __( 'Order', 'brands-for-woocommerce' ),
  130. // 'description' => __( 'Order for output the brand ', 'brands-for-woocommerce' ),
  131. // 'default' => 0,
  132. // ),
  133. 'br_brand_featured' => array(
  134. 'type' => 'checkbox',
  135. "label" => __( 'Featured', 'brands-for-woocommerce' ),
  136. 'description' => __( 'Featured brands can be output first or you may select to show featured brands only', 'brands-for-woocommerce' ),
  137. 'default' => '',
  138. ),
  139. 'br_brand_url' => array(
  140. 'type' => 'url',
  141. "label" => __( 'URL', 'brands-for-woocommerce' ),
  142. 'description' => __( 'Link to the brand page or to the external website', 'brands-for-woocommerce' ),
  143. 'default' => '',
  144. ),
  145. // 'br_brand_color' => array(
  146. // 'type' => 'color',
  147. // "label" => __( 'Color', 'brands-for-woocommerce' ),
  148. // 'default' => '#000000',
  149. // ),
  150. );
  151. $this->values = array(
  152. 'settings_name' => 'br-product_brand-options',
  153. 'option_page' => 'br-product_brand',
  154. 'premium_slug' => 'woocommerce-brands',
  155. 'free_slug' => 'brands-for-woocommerce',
  156. );
  157. // List of the features missed in free version of the plugin
  158. $this->feature_list = array();
  159. $this->framework_data['fontawesome_frontend'] = true;
  160. $this->active_libraries = array('addons', 'popup');
  161. parent::__construct( $this );
  162. if ( $this->init_validation() ) {
  163. add_action ( 'init', array( $this, 'register_taxonomy' ) );
  164. $options = $this->get_option();
  165. add_filter( 'br_brands_options_to_update', array($this, 'options_to_update'), 10 );
  166. add_action ( 'init', array( $this, 'update_from_older' ) );
  167. add_filter( 'berocket_framework_item_content_ajax_button', array( $this, 'ajax_button' ), 10, 6 );
  168. add_action( "wp_ajax_br_brands_clear_cache", array ( $this, 'clear_cache_ajax' ) );
  169. add_action( "wp_ajax_nopriv_br_brands_clear_cache", array ( $this, 'clear_cache_ajax' ) );
  170. add_action( "wp_ajax_br_get_brands", array ( $this, 'br_get_brands' ) );
  171. add_action( "wp_ajax_nopriv_br_get_brands", array ( $this, 'br_get_brands' ) );
  172. add_action( "wp_ajax_br_brands_save_order", array ( $this, 'save_order' ) );
  173. add_action( "wp_ajax_nopriv_br_brands_save_order", array ( $this, 'save_order' ) );
  174. add_action( "wp_ajax_br_brands_save_all_orders", array ( $this, 'save_all_orders' ) );
  175. add_action( "wp_ajax_nopriv_br_brands_save_all_orders", array ( $this, 'save_all_orders' ) );
  176. add_action( "wp_ajax_br_product_brand_settings_save", array ( $this, 'save_settings' ) );
  177. add_action( "woocommerce_archive_description", array ( $this, 'description' ), 5 );
  178. add_action ( "widgets_init", array ( $this, 'widgets_init' ) );
  179. add_action ( "woocommerce_duplicate_product", array ( $this, 'woocommerce_duplicate_product' ), 10, 2 );
  180. // add_filter( 'woocommerce_product_export_column_names', array ( $this, 'brand_product_export_column_names' ) );
  181. add_filter( 'woocommerce_product_export_product_default_columns', array ( $this, 'brand_product_export_column_names' ) );
  182. $taxonimy_name = self::$taxonomy_name;
  183. add_filter( "woocommerce_product_export_product_column_$taxonimy_name", array ( $this, 'brand_export_product_column_brand_taxonomy' ), 10, 2 );
  184. add_filter( 'woocommerce_csv_product_import_mapping_options', array ( $this, 'brand_product_export_column_names' ) );
  185. add_filter( 'woocommerce_csv_product_import_mapping_default_columns', array ( $this, 'brand_product_import_mapping_default_columns' ) );
  186. add_filter( 'woocommerce_product_importer_parsed_data', array ( $this, 'brand_product_importer_parsed_data' ), 10, 2 );
  187. add_filter( 'woocommerce_product_import_inserted_product_object', array ( $this, 'brand_product_import_inserted_product_object' ), 10, 2 );
  188. // add_action ( "import_end", array ( $this, 'set_default_meta_values' ) );
  189. add_shortcode( 'brands_product_thumbnail', array( $this, 'shortcode_brands_product_thumbnail' ) );
  190. add_shortcode( 'brands_info', array( $this, 'brands_info_shortcode' ) );
  191. add_shortcode( 'product_brands_info', array( $this, 'product_brands_info_shortcode' ) );
  192. add_shortcode( 'brands_products', array( $this, 'products_shortcode' ) );
  193. add_shortcode( 'brands_list', array( $this, 'brands_list_shortcode' ) );
  194. add_shortcode( 'brands_catalog', array( $this, 'brands_catalog_shortcode' ) );
  195. add_shortcode( 'brands_by_name', array( $this, 'brands_catalog_shortcode' ) ); // for older versions
  196. add_filter( 'template_include', array( $this, 'template_loader' ) );
  197. add_action( 'current_screen', array( $this, 'register_permalink_option' ) );
  198. add_filter( 'berocket_filter_filter_type_array', array( $this, 'filter_type_array' ) );
  199. add_filter( 'BeRocket_updater_menu_order_sub_order', array($this, 'menu_order_sub_order') );
  200. //WC shortcode compatibility
  201. add_filter('shortcode_atts_products', array($this, 'wc_shortcode_atts'), 10, 3);
  202. add_filter('woocommerce_shortcode_products_query', array($this, 'wc_shortcode_query'), 10, 2);
  203. add_filter( 'br_brands_options_to_update', array($this, 'options_to_update'), 10 );
  204. add_filter( 'wc_get_template', array($this, 'get_brands_template'), 10, 5 );
  205. add_filter( 'woocommerce_get_breadcrumb', array($this, 'remove_brand_crumb' ), 20, 2 );
  206. }
  207. add_filter('parent_file', array($this, 'select_menu'));
  208. add_filter('submenu_file', array($this, 'select_submenu'));
  209. }
  210. public function init_validation() {
  211. return ( ( is_plugin_active( 'woocommerce/woocommerce.php' ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) &&
  212. br_get_woocommerce_version() >= 2.1 );
  213. }
  214. public function widgets_init() {
  215. register_widget("berocket_product_brand_widget");
  216. register_widget("berocket_product_brand_description_widget");
  217. register_widget("berocket_product_list_widget");
  218. register_widget("berocket_alphabet_brand_widget");
  219. }
  220. public function template_loader( $template ) {
  221. $find = array( 'woocommerce.php' );
  222. $file = '';
  223. if ( is_tax( self::$taxonomy_name ) ) {
  224. $term = get_queried_object();
  225. $woocommerce_url = apply_filters( 'woocommerce_template_url', 'woocommerce/' );
  226. $file = 'taxonomy-' . $term->taxonomy . '.php';
  227. $find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
  228. $find[] = $woocommerce_url . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
  229. $find[] = $file;
  230. $find[] = $woocommerce_url . $file;
  231. }
  232. if ( $file ) {
  233. $template = locate_template( $find );
  234. if ( ! $template ) $template = product_brand_TEMPLATE_PATH . $file;
  235. }
  236. return $template;
  237. }
  238. public function get_brands_template( $located, $template_name, $args, $template_path, $default_path ) {
  239. if ( is_tax( self::$taxonomy_name ) && $template_name == 'loop/result-count.php' ) {
  240. $located = plugin_dir_path( __FILE__ ) . 'templates/result-count.php';
  241. }
  242. return $located;
  243. }
  244. public function ajax_button( $html, $field_item, $field_name, $value, $class, $extra ) {
  245. $html .= '<label>';
  246. if ( ! empty( $field_item[ 'label_be_for' ] ) ) {
  247. $html .= "<span class='br_label_be_for'>{$field_item[ 'label_be_for' ]}</span>";
  248. }
  249. $html .= "<input type='button' name='$field_name' value='" . htmlentities( $value ) . "' $class $extra />";
  250. if ( ! empty( $field_item[ 'label_for' ] ) ) {
  251. $html .= "<span class='br_label_for'>{$field_item[ 'label_for' ]}</span>";
  252. }
  253. $html .= '</label>';
  254. return $html;
  255. }
  256. public function shortcode_brands_product_thumbnail($atts = array()) {
  257. ob_start();
  258. $this->description_post($atts);
  259. $return = ob_get_clean();
  260. return apply_filters('shortcode_brands_product_thumbnail_return', $return, $atts);
  261. }
  262. public function brands_info_shortcode( $atts = array() ) {
  263. $default = array('type' => 'name,image,description,banner,link,related', 'id' => false);
  264. $atts = !empty( $atts ) && is_array( $atts ) ? array_merge( $default, $atts ) : $default;
  265. if( $atts['type'] == 'all' ) {
  266. $atts['type'] = $default['type'];
  267. }
  268. $values = explode(',', $atts['type']);
  269. if( empty($values) || ! is_array($values) || count($values) == 0 ) {
  270. return;
  271. }
  272. $atts['banner_display'] = 0;
  273. $atts['display_description'] = 0;
  274. $atts['display_link'] = 0;
  275. $atts['display_title'] = 0;
  276. $atts['thumbnail_display'] = 0;
  277. $atts['related_products_display'] = 0;
  278. $atts['featured'] = 0;
  279. $show_elements = array(
  280. 'name' => 'display_title',
  281. 'banner' => 'banner_display',
  282. 'image' => 'thumbnail_display',
  283. 'description' => 'display_description',
  284. 'link' => 'display_link',
  285. 'related' => 'related_products_display',
  286. );
  287. foreach ( $values as $value ) {
  288. $atts[ $show_elements[$value] ] = 1;
  289. }
  290. if ( !empty( $atts['image'] ) ) {
  291. $atts = $this->parse_image_options( $atts, $atts['image'], 'thumbnail' );
  292. }
  293. if ( !empty( $atts['banner'] ) ) {
  294. $atts = $this->parse_image_options( $atts, $atts['banner'], 'banner' );
  295. }
  296. ob_start();
  297. the_widget( 'berocket_product_brand_description_widget', $atts );
  298. $return = ob_get_clean();
  299. return apply_filters( 'brands_info_shortcode_return', $return, $atts );
  300. // if( empty( $atts['id'] ) ) {
  301. // if( ! is_tax( self::$taxonomy_name ) || !get_query_var( 'term' ) ) {
  302. // return;
  303. // }
  304. // $term = get_term_by( 'term_id', get_query_var( 'term' ), self::$taxonomy_name );
  305. // } else {
  306. // $term = get_term_by( 'term_id', $atts['id'], self::$taxonomy_name );
  307. // }
  308. // if ( empty( $term ) ) return;
  309. // ob_start();
  310. // do_action('brands_info_before', $term, $atts);
  311. // $image = get_term_meta( $term->term_id, 'brand_image_url', true );
  312. // foreach($values as $value) {
  313. // if( $value == 'name' ) {
  314. // echo '', $term->name, '';
  315. // } elseif( $value == 'image' ) {
  316. // echo '<img src="', $image, '" alt="', $term->name, '">';
  317. // } elseif( $value == 'description' ) {
  318. // echo '<div class="br_brand_description">', term_description($term), '</div>';
  319. // }
  320. // }
  321. // do_action('brands_info_after', $term, $atts);
  322. // $return = ob_get_clean();
  323. // return apply_filters('shortcode_brands_info_return', $return, $term, $atts);
  324. }
  325. public function parse_image_options( $atts, $image_options, $image_name ) {
  326. $image_options = explode( ',', $image_options );
  327. foreach ( $image_options as $option ) {
  328. $option = explode( ':', $option );
  329. $atts["{$image_name}_{$option[0]}"] = $option[1];
  330. }
  331. return $atts;
  332. }
  333. public function product_brands_info_shortcode($atts = array()) {
  334. $default = array('type' => 'name,image,description,link', 'product_id' => false);
  335. if( ! empty($atts) && is_array($atts) ) {
  336. $atts = array_merge($default, $atts);
  337. } else {
  338. $atts = $default;
  339. }
  340. if( empty ($atts['type']) ) {
  341. return;
  342. }
  343. if($atts['type'] == 'all') {
  344. $atts['type'] = $default['type'];
  345. }
  346. $values = explode(',', $atts['type']);
  347. if( empty($values) || ! is_array($values) || count($values) == 0 ) {
  348. return;
  349. }
  350. if( empty($atts['product_id']) ) {
  351. global $wp_query;
  352. $product_id = $wp_query->queried_object->ID;
  353. } else {
  354. $product_id = $atts['product_id'];
  355. }
  356. $terms = get_the_terms( $product_id, self::$taxonomy_name );
  357. if( $terms === false || is_wp_error($terms) ) {
  358. return;
  359. }
  360. $term = $terms[0];
  361. ob_start();
  362. do_action('product_brands_info_before', $term, $atts);
  363. $image = get_term_meta( $term->term_id, 'brand_image_url', true );
  364. foreach($values as $value) {
  365. if( $value == 'name' ) {
  366. echo '<h2 class="brand-name">', $term->name, '</h2>';
  367. } elseif( $value == 'image' ) {
  368. echo '<img class="brand-image col-md-3" src="', $image, '" alt="', $term->name, '">';
  369. } elseif( $value == 'description' ) {
  370. echo '<div class="br_brand_description col-md-9">', term_description($term), '</div>';
  371. }
  372. }
  373. do_action('product_brands_info_after', $term, $atts);
  374. $return = ob_get_clean();
  375. return apply_filters('shortcode_product_brands_info_return', $return, $term, $atts);
  376. }
  377. public function brands_catalog_shortcode( $atts = array() ) {
  378. if ( !is_array( $atts ) ) $atts = array();
  379. if ( !empty( $atts['position'] ) ) {
  380. $positions = array(
  381. 1 => 'left',
  382. 2 => 'right',
  383. 3 => 'above',
  384. );
  385. if ( $atts['position'] == 4 ) {
  386. $atts['show_all'] = 1;
  387. $atts['img_align'] = 'left';
  388. } else if ( is_numeric( $atts['position'] ) ) {
  389. $atts['show_all'] = 0;
  390. $atts['img_align'] = $positions[$atts['position']];
  391. }
  392. }
  393. if ( empty( $atts['use_name'] ) ) $atts['use_name'] = 0;
  394. if ( empty( $atts['img'] ) ) $atts['img'] = 0;
  395. if ( $atts['use_name'] === 0 && $atts['img'] === 0 ) $atts['use_name'] = 1;
  396. $atts['cache_key'] = $this->get_cache_key();
  397. ob_start();
  398. the_widget( 'berocket_alphabet_brand_widget', $atts );
  399. $return = ob_get_clean();
  400. return apply_filters('brands_by_name_shortcode_return', $return, $atts);
  401. }
  402. public function brands_list_shortcode($atts = array()) {
  403. if ( !is_array( $atts ) ) $atts = array();
  404. if ( !empty( $atts['padding'] ) ) $atts['padding'] = intval( $atts['padding'] );
  405. $atts['cache_key'] = $this->get_cache_key();
  406. if ( empty( $atts['slider'] ) ) $atts['slider'] = 0;
  407. if ( empty( $atts['featured_first'] ) ) $atts['featured_first'] = 0;
  408. ob_start();
  409. the_widget( 'berocket_product_brand_widget', $atts);
  410. $return = ob_get_clean();
  411. return apply_filters('brands_list_shortcode_return', $return, $atts);
  412. }
  413. public function products_shortcode($atts = array()) {
  414. if ( !is_array( $atts ) ) $atts = array();
  415. if ( empty( $atts['brands'] ) ) {
  416. if( !empty( $atts['brand_id'] ) ) {
  417. $atts['brands'] = $atts['brand_id'];
  418. $atts['brand_field'] = 'id';
  419. } else if( !empty( $atts['brand_slug'] ) ) {
  420. $atts['brands'] = $atts['brand_slug'];
  421. $atts['brand_field'] = 'slug';
  422. }
  423. }
  424. if ( empty( $atts['brands'] ) ) return;
  425. $atts['brands'] = explode( ',', $atts['brands'] );
  426. $atts['cache_key'] = $this->get_cache_key();
  427. ob_start();
  428. the_widget( 'berocket_product_list_widget', $atts );
  429. $return = ob_get_clean();
  430. // $atts = shortcode_atts( array(
  431. // 'columns' => '4',
  432. // 'orderby' => 'title',
  433. // 'order' => 'asc',
  434. // 'brand_id' => '',
  435. // 'brand_slug'=> '',
  436. // 'operator' => 'IN',
  437. // 'per_page' => '12'
  438. // ), $atts );
  439. // if ( empty($atts['brand_id']) && empty($atts['brand_slug']) ) return '';
  440. // // Default ordering args
  441. // $ordering_args = WC()->query->get_catalog_ordering_args( $atts['orderby'], $atts['order'] );
  442. // $meta_query = WC()->query->get_meta_query();
  443. // if( ! empty($atts['brand_id']) ) {
  444. // $brand = $atts['brand_id'];
  445. // $brand_field = 'id';
  446. // } elseif( ! empty($atts['brand_slug']) ) {
  447. // $brand = $atts['brand_slug'];
  448. // $brand_field = 'slug';
  449. // }
  450. // if( empty($atts['per_page']) ) {
  451. // unset($atts['per_page']);
  452. // }
  453. // $query_args = array(
  454. // 'post_type' => 'product',
  455. // 'post_status' => 'publish',
  456. // 'orderby' => $ordering_args['orderby'],
  457. // 'order' => $ordering_args['order'],
  458. // 'posts_per_page' => (empty($atts['per_page']) ? '12' : $atts['per_page']),
  459. // 'meta_query' => $meta_query,
  460. // 'tax_query' => array(
  461. // array(
  462. // 'taxonomy' => self::$taxonomy_name,
  463. // 'terms' => explode( ',', $brand ),
  464. // 'field' => $brand_field,
  465. // 'operator' => $atts['operator']
  466. // )
  467. // )
  468. // );
  469. // if ( isset( $ordering_args['meta_key'] ) ) {
  470. // $query_args['meta_key'] = $ordering_args['meta_key'];
  471. // }
  472. // $return = $this->product_loop( $query_args, $atts, 'product_cat' );
  473. // // Remove ordering query arguments
  474. // WC()->query->remove_ordering_args();
  475. return apply_filters('brands_products_shortcode_return', $return, $atts);
  476. }
  477. private function product_loop( $query_args, $atts, $loop_name ) {
  478. global $woocommerce_loop;
  479. $products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $query_args, $atts, $loop_name ) );
  480. $columns = absint( $atts['columns'] );
  481. $woocommerce_loop['columns'] = $columns;
  482. $woocommerce_loop['name'] = $loop_name;
  483. ob_start();
  484. if ( $products->have_posts() ) {
  485. ?>
  486. <?php do_action( "woocommerce_shortcode_before_{$loop_name}_loop" ); ?>
  487. <?php woocommerce_product_loop_start(); ?>
  488. <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  489. <?php wc_get_template_part( 'content', 'product' ); ?>
  490. <?php endwhile; // end of the loop. ?>
  491. <?php woocommerce_product_loop_end(); ?>
  492. <?php do_action( "woocommerce_shortcode_after_{$loop_name}_loop" ); ?>
  493. <?php
  494. } else {
  495. do_action( "woocommerce_shortcode_{$loop_name}_loop_no_results" );
  496. }
  497. woocommerce_reset_loop();
  498. wp_reset_postdata();
  499. return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
  500. }
  501. public function register_taxonomy () {
  502. $permalink_option = get_option( 'berocket_brands_permalink' );
  503. if( function_exists('wc_get_page_id') ) {
  504. $shop_page_id = wc_get_page_id( 'shop' );
  505. } else {
  506. $shop_page_id = woocommerce_get_page_id( 'shop' );
  507. }
  508. $base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';
  509. $category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit( $base_slug ) : '';
  510. register_taxonomy( self::$taxonomy_name,
  511. array('product'),
  512. array(
  513. 'hierarchical' => true,
  514. 'update_count_callback' => '_update_post_term_count',
  515. "label" => __( 'Brands', 'brands-for-woocommerce'),
  516. 'labels' => array(
  517. 'name' => __( 'Brands', 'brands-for-woocommerce' ),
  518. 'back_to_items' => __( 'Back to Brands', 'brands-for-woocommerce' ),
  519. 'not_found' => __( 'No brands found.', 'brands-for-woocommerce' ),
  520. 'singular_name' => __( 'Brand', 'brands-for-woocommerce' ),
  521. 'search_items' => __( 'Search Brands', 'brands-for-woocommerce' ),
  522. 'all_items' => __( 'All Brands', 'brands-for-woocommerce' ),
  523. 'parent_item' => __( 'Parent Brand', 'brands-for-woocommerce' ),
  524. 'parent_item_colon' => __( 'Parent Brand:', 'brands-for-woocommerce' ),
  525. 'edit_item' => __( 'Edit Brand', 'brands-for-woocommerce' ),
  526. 'update_item' => __( 'Update Brand', 'brands-for-woocommerce' ),
  527. 'add_new_item' => __( 'Add New Brand', 'brands-for-woocommerce' ),
  528. 'new_item_name' => __( 'New Brand Name', 'brands-for-woocommerce' )
  529. ),
  530. 'show_ui' => true,
  531. 'show_in_menu' => true,
  532. 'show_admin_column' => true,
  533. 'show_in_nav_menus' => true,
  534. 'show_in_quick_edit' => true,
  535. 'meta_box_cb' => 'post_categories_meta_box',
  536. 'capabilities' => array(
  537. 'manage_terms' => 'manage_product_terms',
  538. 'edit_terms' => 'edit_product_terms',
  539. 'delete_terms' => 'delete_product_terms',
  540. 'assign_terms' => 'assign_product_terms'
  541. ),
  542. 'rewrite' => array(
  543. 'slug' => $category_base . ( empty($permalink_option) ? __( 'brands', 'brands-for-woocommerce' ) : $permalink_option ),
  544. 'with_front' => true,
  545. 'hierarchical' => true
  546. )
  547. )
  548. );
  549. }
  550. public function init () {
  551. global $woocommerce;
  552. add_filter( 'woocommerce_coupon_is_valid', array( $this, 'validate_coupon' ), 10, 3 );
  553. add_filter( 'woocommerce_coupon_get_discount_amount', array( $this, 'apply_discount' ), null, 5 );
  554. parent::init();
  555. $options = $this->get_option();
  556. BeRocket_tooltip_display::$load_tippy = true;
  557. wp_register_style( 'berocket_slick', plugins_url( 'css/slick.css', __FILE__ ) );
  558. wp_register_script( 'berocket_slick', plugins_url( 'js/slick.min.js', __FILE__ ), array( 'jquery' ) );
  559. wp_register_script( 'br_brands_slider', plugins_url( 'js/slider.js', __FILE__ ), array( 'berocket_slick', 'jquery' ) );
  560. wp_register_script( 'br_brands_catalog', plugins_url( 'js/catalog.js', __FILE__ ), array( 'jquery' ) );
  561. wp_register_style( 'berocket_product_brand_style', plugins_url( 'css/frontend.css', __FILE__ ),
  562. "", BeRocket_product_brand_version );
  563. wp_register_script( 'berocket_front', plugins_url( 'js/front.js', __FILE__ ),
  564. array( 'berocket_framework_tippy', 'jquery' ) );
  565. wp_enqueue_style( 'berocket_product_brand_style' );
  566. wp_enqueue_style( 'berocket_tippy' );
  567. wp_enqueue_script( 'berocket_front' );
  568. }
  569. function wc_get_product_brand_ids( $product_id ) {
  570. $product_brands = wc_get_product_term_ids( $product_id, self::$taxonomy_name );
  571. foreach ( $product_brands as $product_cat ) {
  572. $product_brands = array_merge( $product_brands, get_ancestors( $product_cat, self::$taxonomy_name ) );
  573. }
  574. return $product_brands;
  575. }
  576. function wc_get_brands_for_coupon( &$coupon ) {
  577. if ( ! isset( $coupon->in_brands ) && ! isset( $coupon->ex_brands ) ) {
  578. $in_brands = get_post_meta( $coupon->get_id(), self::$taxonomy_name, true );
  579. $ex_brands = get_post_meta( $coupon->get_id(), 'exclude_berocket_brand', true );
  580. $coupon->in_brands = $in_brands;
  581. $coupon->ex_brands = $ex_brands;
  582. } else {
  583. $in_brands = $coupon->in_brands;
  584. $ex_brands = $coupon->ex_brands;
  585. }
  586. return $coupon;
  587. }
  588. public function validate_coupon($valid, $coupon, $coupon_class) {
  589. if ( ! $valid ) return $valid;
  590. $valid = false;
  591. foreach ( $coupon_class->get_items_to_validate() as $item ) {
  592. if ( $coupon->get_exclude_sale_items() && $item->product && $item->product->is_on_sale() ) {
  593. continue;
  594. }
  595. if( $this->is_coupon_applied_to_product($item->product, $coupon) ) {
  596. $valid = true;
  597. break;
  598. }
  599. }
  600. return $valid;
  601. }
  602. public function apply_discount($discount, $amount, $cart_item, $single, $coupon) {
  603. if ( ! is_a( $coupon, 'WC_Coupon' ) || ! $coupon->is_type( array( 'fixed_product', 'percent' ) ) ) {
  604. return $discount;
  605. }
  606. if( $this->is_coupon_applied_to_product($cart_item['data'], $coupon) ) {
  607. return $discount;
  608. } else {
  609. return 0;
  610. }
  611. }
  612. function is_coupon_applied_to_product($product, $coupon) {
  613. $this->wc_get_brands_for_coupon($coupon);
  614. $is_in_brands = ! empty($coupon->in_brands) && is_array($coupon->in_brands) && count($coupon->in_brands) > 0;
  615. $is_ex_brands = ! empty($coupon->ex_brands) && is_array($coupon->ex_brands) && count($coupon->ex_brands) > 0;
  616. if ( ! $is_in_brands && ! $is_ex_brands ) {
  617. return true;
  618. }
  619. $product_brands = $this->wc_get_product_brand_ids( $product->get_id() );
  620. if ( $product->get_parent_id() ) {
  621. $product_brands = array_merge( $product_brands, $this->wc_get_product_brand_ids( $product->get_parent_id() ) );
  622. }
  623. if( ( $is_in_brands && count( array_intersect( $product_brands, $coupon->in_brands ) ) > 0)
  624. || (! $is_in_brands && (! $is_ex_brands || count( array_intersect( $product_brands, $coupon->ex_brands ) ) == 0) ) ) {
  625. return true;
  626. } else {
  627. return false;
  628. }
  629. }
  630. /**
  631. * Function adding styles/scripts and settings to admin_init WordPress action
  632. *
  633. * @access public
  634. *
  635. * @return void
  636. */
  637. public function admin_init () {
  638. parent::admin_init();
  639. wp_enqueue_style( 'wp-color-picker' );
  640. wp_enqueue_style( 'berocket_widget-colorpicker-style' );
  641. wp_enqueue_script( 'berocket_widget-colorpicker' );
  642. global $pagenow;
  643. if( $pagenow == 'edit-tags.php' && !empty( $_GET['taxonomy'] ) && $_GET['taxonomy'] == self::$taxonomy_name ) {
  644. wp_enqueue_script( 'jquery-ui-sortable' );
  645. }
  646. if( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ) )
  647. && !empty( $_GET['taxonomy'] ) && $_GET['taxonomy'] == self::$taxonomy_name ) {
  648. wp_enqueue_script( 'berocket_framework_admin' );
  649. wp_enqueue_style( 'berocket_framework_admin_style' );
  650. }
  651. wp_enqueue_script( 'jquery-ui-sortable' );
  652. wp_enqueue_script( 'jquery-ui-autocomplete' );
  653. wp_enqueue_script( 'berocket_product_brand_admin', plugins_url( 'js/admin.js', __FILE__ ),
  654. array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-autocomplete', 'wp-color-picker' ), BeRocket_product_brand_version );
  655. wp_register_style( 'berocket_product_brand_admin_style', plugins_url( 'css/admin.css', __FILE__ ), "", BeRocket_product_brand_version );
  656. wp_enqueue_style( 'berocket_product_brand_admin_style' );
  657. wp_localize_script( 'berocket_product_brand_admin', 'brandsHelper',
  658. array(
  659. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  660. )
  661. );
  662. add_filter( 'berocket_framework_item_content_toggleswitch', array($this, 'toggleswitch'), 10, 8 );
  663. add_action( 'berocket_brand_add_form_fields', array( $this, 'add_field' ) );
  664. add_action( 'berocket_brand_edit_form_fields', array( $this, 'edit_field' ), 10, 2 );
  665. add_action( 'created_term', array( $this, 'field_save' ), 10, 3 );
  666. add_action( 'edit_term', array( $this, 'field_save' ), 10, 3 );
  667. add_action( 'edit_term', array( $this, 'clear_cache_on_edit_brand' ), 10, 3 );
  668. add_action( 'created_term', array( $this, 'clear_cache_on_edit_brand' ), 10, 3 );
  669. add_action( 'delete_term', array( $this, 'clear_cache_on_edit_brand' ), 10, 3 );
  670. add_action( 'edit_post', array( $this, 'clear_cache_on_edit_post' ), 10, 2 );
  671. add_action( 'save_post', array( $this, 'clear_cache_on_edit_post' ), 10, 2 );
  672. add_filter( 'woocommerce_product_filters', array( $this, 'product_filter' ) );
  673. add_action( 'woocommerce_coupon_options_usage_restriction', array( $this, 'coupon_field' ) );
  674. add_action( 'woocommerce_coupon_options_save', array( $this, 'save_coupon' ) );
  675. // add_filter( 'woocommerce_sortable_taxonomies', array($this, 'add_brands_to_sortable') );
  676. add_filter( 'woocommerce_screen_ids', array($this, 'woocommerce_screen_ids') );
  677. add_filter( "manage_berocket_brand_custom_column", array( $this, 'brand_custom_columns' ), 10, 3 );
  678. add_filter( "manage_edit-berocket_brand_columns", array( $this, 'brand_columns' ) );
  679. add_filter( "manage_edit-berocket_brand_sortable_columns", array( $this, 'brand_sortable_columns' ) );
  680. // add_filter( "manage_berocket_brand_custom_column", array( $this, 'brand_order_columns' ), 10, 3 );
  681. add_action( 'pre_get_terms', array( $this, 'pre_get_brands' ) );
  682. }
  683. public function toggleswitch( $html, $field_item, $field_name, $value, $class, $extra, $option_values, $option_deault_values ) {
  684. $checked = !empty( $option_values ) ? ' checked="checked" ' : '';
  685. $html .=
  686. "<label class='br_toggleswitch'>
  687. {$field_item['label_be_for']}
  688. <span class='br_toggleswitch_slider_container'>
  689. <input type='checkbox' name='$field_name' value='{$field_item['value']}' $checked $class $extra />
  690. <span class='br_toggleswitch_slider'></span>
  691. </span>
  692. {$field_item['label_for']}
  693. </label>";
  694. return $html;
  695. }
  696. // public function add_brands_to_sortable($taxonomies) {
  697. // $taxonomies[] = self::$taxonomy_name;
  698. // return $taxonomies;
  699. // }
  700. public function brand_columns( $columns ) {
  701. $columns['brand_description'] = __( 'Description', 'brands-for-woocommerce' );
  702. $columns['order'] = __( 'Order', 'brands-for-woocommerce' );
  703. unset( $columns['description'] );
  704. return $columns;
  705. }
  706. public function brand_sortable_columns( $columns ) {
  707. $columns['order'] = __( 'Order', 'brands-for-woocommerce' );
  708. return $columns;
  709. }
  710. public function brand_custom_columns( $value, $name, $term_id ) {
  711. if ( $name == 'brand_description' ) {
  712. $value = wp_trim_words( term_description( $term_id ), 15 );
  713. } else if ( $name == 'order' ) {
  714. $order = get_term_meta( $term_id, 'br_brand_order', true );
  715. if ( $order === '' ) $order = 0;
  716. $saving_title = __( 'Saving...', 'brands-for-woocommerce' );
  717. $save_title = __( 'Save', 'brands-for-woocommerce' );
  718. $prev_title = __( 'Level up', 'brands-for-woocommerce' );
  719. $next_title = __( 'Level down', 'brands-for-woocommerce' );
  720. return
  721. "<a href='#order-up' class='berocket_post_set_new_sortable br_brand_order' title='$prev_title'>
  722. <i class='fa fa-arrow-up'></i>
  723. </a>
  724. <span class='berocket_post_set_new_sortable_input'>
  725. <input class='br_brand_order_input' type='number' min='0' value='$order' />
  726. <a class='berocket_post_set_new_sortable_set br_brand_order_save fa fa-arrow-circle-right' data-term_id='$term_id' href='#order-set' title='$save_title'></a>
  727. <div class='br_brand_order_wait'>$saving_title</div>
  728. </span>
  729. <a href='#order-down' class='berocket_post_set_new_sortable br_brand_order' title='$next_title'>
  730. <i class='fa fa-arrow-down'></i>
  731. </a>
  732. <i class='fa fa-bars ui-sortable-handle br-brands-sortable-handler'></i>";
  733. // return $value = '<span class="br-sorted-holder"><i class="fas fa-arrows-alt-v"></i></span>' . get_term_meta( $term_id, 'br_brand_order', true );
  734. }
  735. return $value;
  736. }
  737. // public function sort_brands_by_order( $pieces, $taxonomies, $args ) {
  738. // global $pagenow;
  739. // if( !is_admin() || $pagenow != 'edit-tags.php' || empty( $taxonomies ) || $taxonomies[0] != self::$taxonomy_name ) {
  740. // return $pieces;
  741. // }
  742. // // $pieces['orderby'] = 'ORDER BY tt.br_brand_order';
  743. // // bd($pieces);
  744. // return $pieces;
  745. // }
  746. public function pre_get_brands( $query ) {
  747. global $pagenow;
  748. if ( !is_admin() || $pagenow != 'edit-tags.php' || $query->query_vars['taxonomy'][0] != self::$taxonomy_name ) {
  749. return $query;
  750. }
  751. // $_GET['orderby'] = 'Order';
  752. // $_GET['order'] = 'ASC';
  753. if ( !empty( $_GET['orderby'] ) && $_GET['orderby'] == 'Order' ) {
  754. $query->query_vars['orderby'] = 'order_clause';
  755. $query->query_vars['order'] = isset($_GET['order']) ? $_GET['order'] : "asc";
  756. // the OR relation and the NOT EXISTS clause allow for terms without a meta_value at all
  757. $args = array(
  758. 'order_clause' => array(
  759. 'key' => 'br_brand_order',
  760. 'type' => 'NUMERIC'
  761. )
  762. );
  763. $query->meta_query = new WP_Meta_Query( $args );
  764. }
  765. return $query;
  766. }
  767. public function woocommerce_screen_ids($screens) {
  768. $screens[] = 'edit-berocket_brand';
  769. return $screens;
  770. }
  771. public function register_permalink_option() {
  772. $screen = get_current_screen();
  773. $default_values = '';
  774. if($screen->id == 'options-permalink') {
  775. $this->save_permalink_option();
  776. $this->_register_permalink_option();
  777. }
  778. }
  779. public function _register_permalink_option() {
  780. add_settings_section(
  781. 'berocket_permalinks_brand',
  782. $this->info['norm_name'],
  783. array($this, 'permalink_input_section'),
  784. 'permalink'
  785. );
  786. }
  787. function permalink_input_section() {
  788. set_query_var( 'norm_name', $this->info['norm_name'] );
  789. $this->br_get_template_part( 'permalink_option' );
  790. }
  791. public function save_permalink_option() {
  792. if ( isset( $_POST['berocket_brands_permalink'] ) ) {
  793. $option_values = $_POST['berocket_brands_permalink'];
  794. update_option( 'berocket_brands_permalink', $option_values );
  795. }
  796. }
  797. private function get_fields( $term_id = false ) {
  798. global $pagenow;
  799. $fields = ( $pagenow == 'edit-tags.php' ) ? '' : '<table class="form-table" role="presentation">';
  800. foreach ( $this->attributes as $name => $attribute ) {
  801. $value = $term_id ? get_term_meta( $term_id, $name, true ) :
  802. ( isset( $attribute['default'] ) ? $attribute['default'] : '' );
  803. $type = $attribute['type'];
  804. $fields .= ( $pagenow == 'edit-tags.php' ) ?
  805. "<div class='form-field term-$name-wrap'>
  806. <label class='br_brand_$type' for='$name'>{$attribute['label']}</label>"
  807. : "<tr class='form-field term-$name-wrap'>
  808. <th scope='row'><label class='br_brand_$type' for='$name'>{$attribute['label']}</label></th>
  809. <td>";
  810. switch ( $type ) {
  811. case 'image':
  812. $select_upload = $value ?
  813. berocket_font_select_upload( '', 'br_brand_options_ajax_load_icon', $attribute['image_name'], @ $value, false)
  814. : berocket_font_select_upload( '', 'br_brand_options_ajax_load_icon', $attribute['image_name'], '', false);
  815. $fields .=
  816. "<div id='$name' class='br_brands_image'>$select_upload</div>";
  817. break;
  818. case 'color':
  819. $fields .=
  820. "<input type='text' id='$name' name='$name' value='$value' class='br_brand_colorpicker' />";
  821. break;
  822. case 'checkbox':
  823. $is_checked = empty( $value ) ? '' : 'checked="checked"';
  824. $fields .=
  825. "<input type='checkbox' id='$name' name='$name' value='1' $is_checked />";
  826. break;
  827. case 'products_selector':
  828. $fields .= br_products_selector( $name, $value, array(
  829. 'type' => 'products',
  830. // label] => Blocking Products
  831. // label_be_for] => No one of this products in cart
  832. 'name' => $name,
  833. // extra => id='br_minmax_products_blocking'
  834. 'value' => $value,
  835. // tr_class] =>
  836. // td_class] =>
  837. // label_for] =>
  838. ));
  839. break;
  840. case 'category_checklist':
  841. $cat_ids = empty($value) ? array() : array_map( function($v) { $term = get_term_by( 'name', $v, 'product_cat' ); return $term->term_id; }, $value );
  842. $fields .= '<ul class="br_brand_product_categories">'
  843. . wp_terms_checklist( 0, array(
  844. 'taxonomy' => 'product_cat',
  845. 'walker' => new Br_Walker_Category_Checklist,
  846. 'selected_cats' => $cat_ids,
  847. 'checked_ontop' => false,
  848. 'echo' => false,
  849. ) ) . '</ul>';
  850. break;
  851. default:
  852. $args = empty( $attribute['attributes'] ) ? ''
  853. : implode( ' ', array_map( function( $key, $value ) { return "$key='$value'";},
  854. array_keys( $attribute['attributes'] ), $attribute['attributes'] ) );
  855. $fields .= "<input name='$name' id='$name' type='{$attribute['type']}' value='$value' $args />";
  856. break;
  857. }
  858. if ( !empty( $attribute['description'] ) ) {
  859. $fields .= "<p>{$attribute['description']}</p>";
  860. }
  861. $fields .= ( $pagenow == 'edit-tags.php' ) ? '</div>' : '</td></tr>' ;
  862. }
  863. if ( $pagenow == 'edit-tags.php' ) $fields .= '</table>';
  864. return $fields;
  865. }
  866. public function add_field () {
  867. echo $this->get_fields();
  868. }
  869. public function edit_field ( $term, $taxonomy ) {
  870. echo $this->get_fields( $term->term_id );
  871. }
  872. public function field_save( $term_id, $tt_id, $taxonomy ) {
  873. if ( $taxonomy != self::$taxonomy_name ) return;
  874. foreach ( $this->attributes as $name => $attribute ) {
  875. switch ( $attribute['type'] ) {
  876. case 'image':
  877. $image_name = $attribute['image_name'];
  878. if ( isset( $_POST[$image_name] ) ) {
  879. update_term_meta( $term_id, $name, $_POST[$image_name] );
  880. }
  881. break;
  882. case 'checkbox':
  883. if ( !empty( $_POST[$name] ) ) {
  884. update_term_meta( $term_id, $name, $_POST[$name] );
  885. } else {
  886. update_term_meta( $term_id, $name, false );
  887. }
  888. break;
  889. case 'category_checklist':
  890. if ( !empty( $_POST[$name] ) && !empty( $_POST[$name]['product_cat'] ) ) {
  891. update_term_meta( $term_id, $name, $_POST[$name]['product_cat'] );
  892. } else {
  893. update_term_meta( $term_id, $name, array() );
  894. }
  895. break;
  896. default:
  897. if ( isset( $_POST[$name] ) ) {
  898. update_term_meta( $term_id, $name, $_POST[$name] );
  899. }
  900. break;
  901. }
  902. }
  903. if ( empty( get_term_meta( $term_id, 'br_brand_order' ) ) ) {
  904. add_term_meta( $term_id, 'br_brand_order', 0 );
  905. }
  906. }
  907. public function clear_cache_on_edit_brand( $term_id, $tt_id, $taxonomy ) {
  908. if ( $taxonomy != self::$taxonomy_name ) return;
  909. $this->clear_cache();
  910. }
  911. public function clear_cache_on_edit_post( $post_ID, $post ) {
  912. // if ( get_post_type( $post_ID ) == 'product' ) {
  913. $this->clear_cache();
  914. // return;
  915. // }
  916. // $this->clear_cache( "{$this->cache_key}_$post_ID" );
  917. }
  918. public function description() {
  919. if( ! is_tax( self::$taxonomy_name ) ) {
  920. return;
  921. }
  922. if ( ! get_query_var( self::$taxonomy_name ) && ! get_query_var( 'term' ) ) {
  923. return;
  924. }
  925. $term_find = get_query_var( self::$taxonomy_name );
  926. $term_find = empty( $term_find ) ? get_query_var( 'term' ) : $term_find;
  927. $term = get_term_by( 'slug', $term_find, self::$taxonomy_name );
  928. if( empty( $term ) ) {
  929. return;
  930. }
  931. $options = $this->get_option();
  932. if ( empty( $options['link_text'] ) ) $options['link_text'] = $this->defaults['link_text'];
  933. set_query_var( 'options', $options );
  934. set_query_var( 'brand_term', $term );
  935. set_query_var( 'brand_banner', get_term_meta( $term->term_id, 'brand_banner_url', true ) );
  936. set_query_var( 'brand_thumbnail', get_term_meta( $term->term_id, 'brand_image_url', true ) );
  937. set_query_var( 'brand_url', get_term_meta( $term->term_id, 'br_brand_url', true ) );
  938. set_query_var( 'tooltip', BeRocket_product_brand::get_tooltip( $term->term_id ) );
  939. $this->br_get_template_part( 'description' );
  940. remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
  941. remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
  942. }
  943. public function description_post($atts = array()) {
  944. $atts = shortcode_atts( array(
  945. 'post_id' => '',
  946. 'width' => '35%',
  947. 'height' => '',
  948. 'position' => 'right',
  949. 'image' => '1',
  950. 'url' => '',
  951. ), $atts );
  952. if( empty($atts['post_id']) ) {
  953. $atts['post_id'] = get_the_ID();
  954. if( empty($atts['post_id']) ) {
  955. return;
  956. }
  957. }
  958. $terms = get_the_terms( $atts['post_id'], self::$taxonomy_name );
  959. if( empty($terms) ) {
  960. return;
  961. }
  962. if( ! empty($terms) && is_array($terms) ) {
  963. foreach($terms as $term) {
  964. $image = get_term_meta( $term->term_id, 'brand_image_url', true );
  965. if( ! empty($atts['url']) ) {
  966. echo '<a href="' . get_term_link( (int)$term->term_id ) . '">';
  967. }
  968. if( ! empty($image) && ! empty($atts['image']) ) {
  969. echo '<img class="berocket_brand_post_image" src="', $image, '" alt="', $term->name, '" style="',
  970. (empty($atts['width']) ? '' : 'width:'.$atts['width'].';'),
  971. (empty($atts['height']) ? '' : 'height:'.$atts['height'].';'),
  972. (empty($atts['position']) ? '' : 'float:'.$atts['position'].';'),
  973. '">';
  974. } else {
  975. echo '<span class="berocket_brand_post_image_name" style="display: block;',
  976. (empty($atts['width']) ? '' : 'width:'.$atts['width'].';'),
  977. (empty($atts['height']) ? '' : 'height:'.$atts['height'].';'),
  978. (empty($atts['position']) ? '' : 'float:'.$atts['position'].';'),
  979. '">', @ $term->name, '</span>';
  980. }
  981. if( ! empty($atts['url']) ) {
  982. echo '</a>';
  983. }
  984. }
  985. }
  986. }
  987. public function product_filter( $filters ) {
  988. global $wp_query;
  989. $current_product_brand = (! empty( $wp_query->query[self::$taxonomy_name] ) ? $wp_query->query[self::$taxonomy_name] : '');
  990. $terms = get_terms( self::$taxonomy_name );
  991. if ( empty($terms) ) {
  992. return $filters;
  993. }
  994. $args = array(
  995. 'pad_counts' => 1,
  996. 'count' => 1,
  997. 'hierarchical' => 1,
  998. 'hide_empty' => 1,
  999. 'show_uncategorized' => 1,
  1000. 'orderby' => 'name',
  1001. 'selected' => $current_product_brand,
  1002. 'menu_order' => false
  1003. );
  1004. $filters = $filters . PHP_EOL;
  1005. $taxonomy_name = self::$taxonomy_name;
  1006. $filters .= "<select name='$taxonomy_name' class='dropdown_berocket_brand'>";
  1007. $filters .= '<option value="" ' . selected( $current_product_brand, '', false ) . '>' . __( 'Select a brand', 'brands-for-woocommerce' ) . '</option>';
  1008. $filters .= wc_walk_category_dropdown_tree( $terms, 0, $args );
  1009. $filters .= "</select>";
  1010. return $filters;
  1011. }
  1012. public function coupon_field () {
  1013. global $post;
  1014. $categories = get_terms( self::$taxonomy_name, 'orderby=name&hide_empty=0' );
  1015. ?>
  1016. <div class="options_group">
  1017. <p class="form-field">
  1018. <label for="berocket_brand"><?php _e( 'Product brands', 'brands-for-woocommerce' ); ?></label>
  1019. <select id="berocked_brand" name="berocket_brand[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'Any brand', 'brands-for-woocommerce' ); ?>">
  1020. <?php
  1021. $category_ids = (array) get_post_meta( $post->ID, self::$taxonomy_name, true );
  1022. if ( $categories && is_array($categories) ) foreach ( $categories as $cat ) {
  1023. echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
  1024. }
  1025. ?>
  1026. </select>
  1027. <?php
  1028. if( function_exists('wc_help_tip') ) {
  1029. echo wc_help_tip( __( 'Products with these brands will be discounted', 'brands-for-woocommerce' ) );
  1030. } ?>
  1031. </p>
  1032. <p class="form-field">
  1033. <label for="exclude_berocket_brand"><?php _e( 'Exclude brands', 'brands-for-woocommerce' ); ?></label>
  1034. <select id="exclude_berocked_brand" name="exclude_berocket_brand[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php _e( 'No brands', 'brands-for-woocommerce' ); ?>">
  1035. <?php
  1036. $category_ids = (array) get_post_meta( $post->ID, 'exclude_berocket_brand', true );
  1037. if ( $categories && is_array($categories) ) foreach ( $categories as $cat ) {
  1038. echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
  1039. }
  1040. ?>
  1041. </select>
  1042. <?php
  1043. if( function_exists('wc_help_tip') ) {
  1044. echo wc_help_tip( __( 'Products with these brands will not be discounted', 'brands-for-woocommerce' ) );
  1045. } ?>
  1046. </p>
  1047. </div>
  1048. <?php
  1049. }
  1050. public function save_coupon($post_id) {
  1051. $berocket_brand = empty( $_POST[self::$taxonomy_name] ) ? array() : $_POST[self::$taxonomy_name];
  1052. $exclude_berocket_brand = empty( $_POST['exclude_berocket_brand'] ) ? array() : $_POST['exclude_berocket_brand'];
  1053. // Save
  1054. update_post_meta( $post_id, self::$taxonomy_name, $berocket_brand );
  1055. update_post_meta( $post_id, 'exclude_berocket_brand', $exclude_berocket_brand );
  1056. }
  1057. public function admin_menu() {
  1058. if( parent::admin_menu() ) {
  1059. add_submenu_page(
  1060. 'woocommerce',
  1061. __( $this->info[ 'norm_name' ] . ' settings', $this->info[ 'domain' ] ),
  1062. __( $this->info[ 'norm_name' ], $this->info[ 'domain' ] ),
  1063. 'manage_options',
  1064. $this->values[ 'option_page' ],
  1065. array(
  1066. $this,
  1067. 'option_form'
  1068. )
  1069. );
  1070. }
  1071. }
  1072. public function admin_settings( $tabs_info = array(), $data = array() ) {
  1073. $align_options = array(
  1074. array("value" => "none", "text" => __( 'none', 'brands-for-woocommerce' )),
  1075. array("value" => "left", "text" => __( 'Left', 'brands-for-woocommerce' )),
  1076. array("value" => "right", "text" => __( 'Right', 'brands-for-woocommerce' )),
  1077. );
  1078. parent::admin_settings(
  1079. array(
  1080. 'General' => array(
  1081. 'icon' => 'cog',
  1082. 'name' => __( 'General', 'brands-for-woocommerce' ),
  1083. ),
  1084. 'Brand Page' => array(
  1085. 'icon' => 'sitemap',
  1086. 'name' => __( 'Brand Page', 'brands-for-woocommerce' ),
  1087. ),
  1088. 'Slider' => array(
  1089. 'icon' => 'arrows-h',
  1090. 'name' => __( 'Slider', 'brands-for-woocommerce' ),
  1091. ),
  1092. 'CSS' => array(
  1093. 'icon' => 'css3',
  1094. 'name' => __( 'CSS', 'brands-for-woocommerce' ),
  1095. ),
  1096. 'Addons' => array(
  1097. 'icon' => 'cog',
  1098. 'name' => __( 'Addons', 'brands-for-woocommerce' ),
  1099. ),
  1100. 'License' => array(
  1101. 'icon' => 'unlock-alt',
  1102. 'name' => __( 'License', 'brands-for-woocommerce' ),
  1103. 'link' => admin_url( 'admin.php?page=berocket_account' )
  1104. ),
  1105. ),
  1106. array(
  1107. 'General' => array(
  1108. 'cache' => array(
  1109. "label" => __('Use cache', 'brands-for-woocommerce'),
  1110. "tr_class" => "br_use_cache",
  1111. "items" => array(
  1112. 'use_cache' => array(
  1113. "type" => "checkbox",
  1114. // "label" => __('Use cache', 'brands-for-woocommerce'),
  1115. "class" => "br_brands_display_options",
  1116. "name" => "use_cache",
  1117. "value" => $this->defaults['use_cache'],
  1118. ),
  1119. 'clear_cache' => array(
  1120. "type" => "ajax_button",
  1121. // "label_be_for" => __('Clear cache', 'brands-for-woocommerce'),
  1122. "label_for" => __('Clear cache after update shortcodes and widgets', 'brands-for-woocommerce'),
  1123. "name" => "clear_cache",
  1124. 'extra' => ' id="br_brands_clear_cache" data-process="' . __('Clearing...', 'brands-for-woocommerce') . '" data-done="' . __('Cleared', 'brands-for-woocommerce') . '"',
  1125. 'class' => 'button action',
  1126. "value" => __( 'Clear', 'brands-for-woocommerce' ),
  1127. ),
  1128. ),
  1129. ),
  1130. 'shortcodes_explanation' => array(
  1131. "section" => "shortcodes_explanation",
  1132. ),
  1133. ),
  1134. 'Brand Page' => array(
  1135. 'display_description' => array(
  1136. "type" => "checkbox",
  1137. "label" => __('Display description', 'brands-for-woocommerce'),
  1138. "name" => "display_description",
  1139. "value" => $this->defaults['display_description'],
  1140. ),
  1141. 'thumbnail' => brfr_image_options( array(
  1142. 'name' => 'thumbnail',
  1143. "label" => __('Thumbnail', 'brands-for-woocommerce'),
  1144. 'defaults' => $this->defaults,
  1145. 'align_options' => $align_options )
  1146. ),
  1147. 'banner' => brfr_image_options( array(
  1148. 'name' => 'banner',
  1149. "label" => __('Banner', 'brands-for-woocommerce'),
  1150. 'defaults' => $this->defaults,
  1151. 'align_options' => $align_options )
  1152. ),
  1153. 'external_link' => array(
  1154. "label" => __('External link', 'brands-for-woocommerce'),
  1155. "tr_class" => "br_nowrap_label",
  1156. "items" => array(
  1157. 'display_link' => array(
  1158. "type" => "checkbox",
  1159. "label_be_for" => __('Display (if URL for the brand is set)', 'brands-for-woocommerce'),
  1160. "class" => "br_brands_display_options",
  1161. "name" => "display_link",
  1162. "value" => $this->defaults['display_link'],
  1163. ),
  1164. 'link_text' => array(
  1165. "type" => "text",
  1166. "label_be_for" => __('Text', 'brands-for-woocommerce'),
  1167. "name" => "link_text",
  1168. "value" => $this->defaults['link_text'],
  1169. ),
  1170. 'link_open_in_new_tab' => array(
  1171. "type" => "checkbox",
  1172. "label_be_for" => __('Open in new tab', 'brands-for-woocommerce'),
  1173. "name" => "link_open_in_new_tab",
  1174. "value" => $this->defaults['link_open_in_new_tab'],
  1175. ),
  1176. ),
  1177. ),
  1178. 'related_products' => array(
  1179. "label" => __('Related products', 'brands-for-woocommerce'),
  1180. "tr_class" => "br_nowrap_label",
  1181. "items" => array(
  1182. 'related_products_display' => array(
  1183. "type" => "checkbox",
  1184. "label_be_for" => __('Display', 'brands-for-woocommerce'),
  1185. "name" => "related_products_display",
  1186. "value" => $this->defaults['related_products_display'],
  1187. "class" => "br_brands_display_options",
  1188. ),
  1189. 'related_products_columns' => array(
  1190. "type" => "number",
  1191. "label_be_for" => __('Columns', 'brands-for-woocommerce'),
  1192. "name" => "related_products_columns",
  1193. "value" => $this->defaults['related_products_columns'],
  1194. "class" => "br_brand_number",
  1195. ),
  1196. 'related_products_per_page' => array(
  1197. "type" => "number",
  1198. "label_be_for" => __('Products per page (blank for all)', 'brands-for-woocommerce'),
  1199. "name" => "related_products_per_page",
  1200. "value" => $this->defaults['related_products_per_page'],
  1201. "class" => "br_brand_number",
  1202. "extra" => "placeholder='" . __( 'All', 'brands-for-woocommerce' ) . "'",
  1203. ),
  1204. 'related_products_orderby' => array(
  1205. "type" => "selectbox",
  1206. "label_be_for" => __('Order by', 'brands-for-woocommerce'),
  1207. "name" => "related_products_order_by",
  1208. "options" => array(
  1209. array( 'value' => 'title', 'text' => __( 'Product title', 'brands-for-woocommerce' ) ),
  1210. array( 'value' => 'name', 'text' => __( 'Product name', 'brands-for-woocommerce' ) ),
  1211. array( 'value' => 'date', 'text' => __( 'Date of creation', 'brands-for-woocommerce' ) ),
  1212. array( 'value' => 'modified', 'text' => __( 'Last modified date', 'brands-for-woocommerce' ) ),
  1213. array( 'value' => 'rand', 'text' => __( 'Random', 'brands-for-woocommerce' ) ),
  1214. ),
  1215. "value" => $this->defaults['related_products_orderby'],
  1216. ),
  1217. 'related_products_order' => array(
  1218. "type" => "selectbox",
  1219. "name" => "related_products_order",
  1220. "options" => array(
  1221. array( 'value' => 'asc', 'text' => __( 'Asc', 'brands-for-woocommerce' ) ),
  1222. array( 'value' => 'desc', 'text' => __( 'Desc', 'brands-for-woocommerce' ) ),
  1223. ),
  1224. "value" => $this->defaults['related_products_order'],
  1225. ),
  1226. 'related_products_slider' => array(
  1227. "type" => "checkbox",
  1228. "label_be_for" => __('Slider', 'brands-for-woocommerce'),
  1229. "name" => "related_products_slider",
  1230. "value" => $this->defaults['related_products_slider'],
  1231. ),
  1232. 'related_products_hide_brands' => array(
  1233. "type" => "checkbox",
  1234. "label_be_for" => __('Hide brands', 'brands-for-woocommerce'),
  1235. "name" => "related_products_hide_brands",
  1236. "value" => $this->defaults['related_products_hide_brands'],
  1237. ),
  1238. ),
  1239. ),
  1240. ),
  1241. 'Slider' => array(
  1242. 'slider_autoplay' => array(
  1243. "type" => "checkbox",
  1244. "label" => __('Autoplay', 'brands-for-woocommerce'),
  1245. "name" => "slider_autoplay",
  1246. "extra" => " id='br_slider_autoplay'",
  1247. "class" => "br_has_dependent_options",
  1248. "value" => $this->defaults['slider_autoplay'],
  1249. ),
  1250. 'slider_autoplay_speed' => array(
  1251. "type" => "number",
  1252. "label" => __('Autoplay Speed', 'brands-for-woocommerce'),
  1253. "label_for" => __('ms', 'brands-for-woocommerce'),
  1254. "name" => "slider_autoplay_speed",
  1255. "class" => "br_slider_autoplay_dependent",
  1256. "value" => $this->defaults['slider_autoplay_speed'],
  1257. ),
  1258. 'slider_change_speed' => array(
  1259. "type" => "number",
  1260. "label" => __('Slide change speed', 'brands-for-woocommerce'),
  1261. "label_for" => __('ms', 'brands-for-woocommerce'),
  1262. "name" => "slider_change_speed",
  1263. "value" => $this->defaults['slider_change_speed'],
  1264. ),
  1265. 'slider_infinite' => array(
  1266. "type" => "checkbox",
  1267. "label" => __('Infinite', 'brands-for-woocommerce'),
  1268. "name" => "slider_infinite",
  1269. "value" => $this->defaults['slider_infinite'],
  1270. ),
  1271. 'slider_arrows' => array(
  1272. "type" => "checkbox",
  1273. "label" => __('Show Arrows', 'brands-for-woocommerce'),
  1274. "name" => "slider_arrows",
  1275. "value" => $this->defaults['slider_arrows'],
  1276. ),
  1277. 'slider_slides_scroll' => array(
  1278. "type" => "number",
  1279. "label" => __('Brands to Scroll', 'brands-for-woocommerce'),
  1280. "label_for" => __('maximum brands to scroll for the widget is number of brands per page for this widget', 'brands-for-woocommerce'),
  1281. "name" => "slider_slides_scroll",
  1282. "value" => $this->defaults['slider_slides_scroll'],
  1283. ),
  1284. 'slider_mode' => array(
  1285. "type" => "toggleswitch",
  1286. "label" => __('Change slide mode', 'brands-for-woocommerce'),
  1287. "label_for" => __('Slide', 'brands-for-woocommerce'),
  1288. "label_be_for" => __('Fade', 'brands-for-woocommerce'),
  1289. "tr_class" => "br_nowrap_label",
  1290. "name" => "slider_mode",
  1291. "value" => $this->defaults['slider_mode'],
  1292. ),
  1293. 'slider_ease' => array(
  1294. "type" => "selectbox",
  1295. "label" => __('Easing', 'brands-for-woocommerce'),
  1296. "name" => "slider_ease",
  1297. "options" => array(
  1298. array('value' => 'linear', 'text' => __( 'Linear', 'brands-for-woocommerce' ) ),
  1299. array('value' => 'ease', 'text' => __( 'Ease', 'brands-for-woocommerce' ) ),
  1300. array('value' => 'ease-in', 'text' => __( 'Ease in', 'brands-for-woocommerce' ) ),
  1301. array('value' => 'ease-out', 'text' => __( 'Ease out', 'brands-for-woocommerce' ) ),
  1302. array('value' => 'ease-in-out', 'text' => __( 'Ease in-out', 'brands-for-woocommerce' ) ),
  1303. array('value' => 'cubic-bezier(.22,.68,0,1.71)', 'text' => __( 'Cubic Bezier 1', 'brands-for-woocommerce' ) ),
  1304. array('value' => 'cubic-bezier(.57,.21,.69,1.25)', 'text' => __( 'Cubic Bezier 2', 'brands-for-woocommerce' ) ),
  1305. array('value' => 'cubic-bezier(0.600,-0.280,0.735,0.045)', 'text' => __( 'Cubic Bezier 3', 'brands-for-woocommerce' ) ),
  1306. array('value' => 'cubic-bezier(.99,.01,.99,.01)', 'text' => __( 'Cubic Bezier 4', 'brands-for-woocommerce' ) ),
  1307. array('value' => 'cubic-bezier(.99,.62,.56,.01)', 'text' => __( 'Cubic Bezier 5', 'brands-for-woocommerce' ) ),
  1308. array('value' => 'cubic-bezier(.59,1.75,.32,-0.61)', 'text' => __( 'Cubic Bezier 6', 'brands-for-woocommerce' ) ),
  1309. ),
  1310. "value" => $this->defaults['slider_ease'],
  1311. ),
  1312. 'slider_stop_focus' => array(
  1313. "type" => "checkbox",
  1314. "label" => __('Stop Autoscroll on Focus', 'brands-for-woocommerce'),
  1315. "name" => "slider_stop_focus",
  1316. "value" => $this->defaults['slider_stop_focus'],
  1317. ),
  1318. 'slider_dots' => array(
  1319. "type" => "checkbox",
  1320. "label" => __('Show dots', 'brands-for-woocommerce'),
  1321. "name" => "slider_dots",
  1322. "extra" => " id='br_slider_dots'",
  1323. "class" => "br_has_dependent_options",
  1324. "value" => 1,
  1325. ),
  1326. 'slider_dots_color' => array(
  1327. "type" => "color",
  1328. "label" => __('Dots color', 'brands-for-woocommerce'),
  1329. "name" => "slider_dots_color",
  1330. "class" => "br_slider_dots_dependent",
  1331. "value" => $this->defaults['slider_dots_color'],
  1332. ),
  1333. ),
  1334. 'CSS' => array(
  1335. 'global_font_awesome_disable' => array(
  1336. "label" => __( 'Disable Font Awesome', "brands-for-woocommerce" ),
  1337. "type" => "checkbox",
  1338. "name" => "fontawesome_frontend_disable",
  1339. "value" => $this->defaults['global_font_awesome_disable'],
  1340. 'label_for' => __('Don\'t loading css file for Font Awesome on site front end. Use it only if you doesn\'t uses Font Awesome icons in widgets or you have Font Awesome in your theme.', 'brands-for-woocommerce'),
  1341. ),
  1342. 'global_fontawesome_version' => array(
  1343. "label" => __( 'Font Awesome Version', "brands-for-woocommerce" ),
  1344. "name" => "fontawesome_frontend_version",
  1345. "type" => "selectbox",
  1346. "options" => array(
  1347. array('value' => '', 'text' => __('Font Awesome 4', 'brands-for-woocommerce')),
  1348. array('value' => 'fontawesome5', 'text' => __('Font Awesome 5', 'brands-for-woocommerce')),
  1349. ),
  1350. "value" => $this->defaults['global_fontawesome_version'],
  1351. "label_for" => __('Version of Font Awesome that will be used on front end. Please select version that you have in your theme', 'brands-for-woocommerce'),
  1352. ),
  1353. array(
  1354. "type" => "textarea",
  1355. "label" => __('Custom CSS', 'brands-for-woocommerce'),
  1356. "name" => "custom_css",
  1357. ),
  1358. ),
  1359. 'Addons' => array(
  1360. array(
  1361. "label" => '',
  1362. 'section' => 'addons'
  1363. ),
  1364. ),
  1365. ) );
  1366. }
  1367. public function section_shortcodes_explanation() {
  1368. $html = '<th scope="row" style="vertical-align: top;">' . __('Shortcodes: click to expand', 'brands-for-woocommerce') . '</th>
  1369. <td>
  1370. <ul class="br_shortcode_info">
  1371. <li>
  1372. <span class="br_shortcode_title">
  1373. <strong><i class="fas fa-caret-right"></i>&nbsp;[brands_list]</strong> - '.__("list of brands", 'brands-for-woocommerce').'
  1374. </span>
  1375. <ul class="br_shortcode_attributes">
  1376. <li><i>title</i> - '.__("title of the brand list", 'brands-for-woocommerce').'</li>
  1377. <li><i>use_name</i> - '.__("display brand name (1 or 0)", 'brands-for-woocommerce').'</li>
  1378. <li><i>per_row</i> - '.__("number of columns for brands list (number of brands per slider)", 'brands-for-woocommerce').'</li>
  1379. <li><i>hide_empty</i> - '.__("hide brands without products (1 or 0)", 'brands-for-woocommerce').'</li>
  1380. <li><i>count</i> - '.__("maximum number of brands", 'brands-for-woocommerce').'</li>
  1381. <li><i>padding</i> - '.__("padding around image and name in pixels (default is 3)", 'brands-for-woocommerce').'</li>
  1382. <li><i>border_color</i> - '.__("border color in HEX (#FFFFFF - white, #000000 - black)", 'brands-for-woocommerce').'</li>
  1383. <li><i>border_width</i> - '.__("border width in pixels", 'brands-for-woocommerce').'</li>
  1384. <li><i>slider</i> - '.__("output mode: slider (1) or list (0)", 'brands-for-woocommerce').'</li>
  1385. <li><i>orderby</i> - '.__("sort brands by:", 'brands-for-woocommerce').'
  1386. <ul>
  1387. <li><i>name</i> - '.__("brand name (default)", 'brands-for-woocommerce').'</li>
  1388. <li><i>count</i> - '.__("number of products", 'brands-for-woocommerce').'</li>
  1389. <li><i>order</i> - '.__("brand order", 'brands-for-woocommerce').'</li>
  1390. <li><i>random</i> - '.__("random order", 'brands-for-woocommerce').'</li>
  1391. <li><i>slug</i> - '.__("brand slug", 'brands-for-woocommerce').'</li>
  1392. <li><i>description</i> - '.__("brand description", 'brands-for-woocommerce').'</li>
  1393. </ul>
  1394. </li>
  1395. <li><i>order</i> - '.__("sorting order:", 'brands-for-woocommerce').'
  1396. <ul>
  1397. <li><i>asc</i> - '.__("ascending (default)", 'brands-for-woocommerce').'</li>
  1398. <li><i>desc</i> - '.__("descending", 'brands-for-woocommerce').'</li>
  1399. </ul>
  1400. </li>
  1401. <li><i>img</i> - '.__("display brand image (1 or 0)", 'brands-for-woocommerce').'</li>
  1402. <li><i>imgh</i> - '.__("brand image height in px or % (i.e. 50%, 100px; default is 64px)", 'brands-for-woocommerce').'</li>
  1403. <li><i>imgw</i> - '.__("brand image width in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1404. <li><i>img_fit</i> - '.__("brand image fit:", 'brands-for-woocommerce').'
  1405. <ul>
  1406. <li><i>cover</i> - '.__("default", 'brands-for-woocommerce').'</li>
  1407. <li><i>contain</i></li>
  1408. <li><i>fill</i></li>
  1409. </ul>
  1410. </li>
  1411. <li><i>img_align</i> - '.__("brand image align to name:", 'brands-for-woocommerce') . '
  1412. <ul>
  1413. <li><i>left</i> - '.__("image left to name", 'brands-for-woocommerce').'</li>
  1414. <li><i>right</i> - '.__("image right to name", 'brands-for-woocommerce').'</li>
  1415. <li><i>under</i> - '.__("image under name", 'brands-for-woocommerce').'</li>
  1416. <li><i>above</i> - '.__("image above name (default)", 'brands-for-woocommerce').'</li>
  1417. </ul>
  1418. </li>
  1419. <li><i>featured_first</i> - '.__("show featured brands first (0 or 1)", 'brands-for-woocommerce').'</li>
  1420. <li><i>hierarchy</i> - '.__("brand image align to name:", 'brands-for-woocommerce') . '
  1421. <ul>
  1422. <li><i>top</i> - ' . __( 'Only top level', 'brands-for-woocommerce' ) . '</li>
  1423. <li><i>children</i> - ' . __( 'Only children (without hierarchy)', 'brands-for-woocommerce' ) . '</li>
  1424. <li><i>expand</i> - ' . __( 'Show full hierarchy', 'brands-for-woocommerce' ) . '</li>
  1425. <li><i>by_click</i> - ' . __( 'Expand by click', 'brands-for-woocommerce' ) . '</li>
  1426. <li><i>all</i> - ' . __( 'All brands without hierarchy (default)', 'brands-for-woocommerce' ) . '</li>
  1427. </ul>
  1428. </li>
  1429. <li><i>include</i> - '.__("brands to display (id list, i.e. include='45,47,52,61')", 'brands-for-woocommerce').'</li>
  1430. <li><i>exclude</i> - '.__("brands to exclude from display (i.e. exclude='45,47,52,61')", 'brands-for-woocommerce').'</li>
  1431. </ul>
  1432. </li>
  1433. <li>
  1434. <span class="br_shortcode_title">
  1435. <strong><i class="fas fa-caret-right"></i>&nbsp;[brands_catalog]</strong> - '.__("brands grouped by name or category", 'brands-for-woocommerce').'
  1436. </span>
  1437. <ul class="br_shortcode_attributes">
  1438. <li><i>title</i> - '.__("title of the brand catalog", 'brands-for-woocommerce').'</li>
  1439. <li><i>use_name</i> - '.__("display brand name", 'brands-for-woocommerce').'</li>
  1440. <li><i>style</i> - '.__("placement of brands:", 'brands-for-woocommerce').'
  1441. <ul>
  1442. <li><i>vertical</i> - '.__("vertically (default)", 'brands-for-woocommerce').'</li>
  1443. <li><i>horizontal</i> - '.__("horizontally", 'brands-for-woocommerce').'</li>
  1444. </ul>
  1445. </li>
  1446. <li><i>column</i> - '.__("number of columns", 'brands-for-woocommerce').'</li>
  1447. <li><i>hide_empty</i> - '.__("hide brands without products (1 or 0)", 'brands-for-woocommerce').'</li>
  1448. <li><i>count</i> - '.__("maximum number of brands", 'brands-for-woocommerce').'</li>
  1449. <li><i>groupby</i> - '.__("group brands by:", 'brands-for-woocommerce').'
  1450. <ul>
  1451. <li><i>alphabet</i> - '.__("brand name (default)", 'brands-for-woocommerce').'</li>
  1452. <li><i>category</i> - '.__("brand category", 'brands-for-woocommerce').'</li>
  1453. <li><i>none</i> - '.__("no group", 'brands-for-woocommerce').'</li>
  1454. </ul>
  1455. </li>
  1456. <li><i>orderby</i> - '.__("sort brands by:", 'brands-for-woocommerce').'
  1457. <ul>
  1458. <li><i>name</i> - '.__("brand name (default)", 'brands-for-woocommerce').'</li>
  1459. <li><i>count</i> - '.__("number of products", 'brands-for-woocommerce').'</li>
  1460. <li><i>order</i> - '.__("brand order", 'brands-for-woocommerce').'</li>
  1461. <li><i>random</i> - '.__("random order", 'brands-for-woocommerce').'</li>
  1462. <li><i>slug</i> - '.__("brand slug", 'brands-for-woocommerce').'</li>
  1463. <li><i>description</i> - '.__("brand description", 'brands-for-woocommerce').'</li>
  1464. </ul>
  1465. </li>
  1466. <li><i>order</i> - '.__("sorting order:", 'brands-for-woocommerce').'
  1467. <ul>
  1468. <li><i>asc</i> - '.__("ascending (default)", 'brands-for-woocommerce').'</li>
  1469. <li><i>desc</i> - '.__("descending", 'brands-for-woocommerce').'</li>
  1470. </ul>
  1471. </li>
  1472. <li><i>img</i> - '.__("display brand image", 'brands-for-woocommerce').'</li>
  1473. <li><i>imgh</i> - '.__("brand image height, in px or % (i.e. 50%, 100px; default is 64px)", 'brands-for-woocommerce').'</li>
  1474. <li><i>imgw</i> - '.__("brand image width, in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1475. <li><i>img_fit</i> - '.__("brand image fit:", 'brands-for-woocommerce').'
  1476. <ul>
  1477. <li><i>cover</i> - '.__("default", 'brands-for-woocommerce').'</li>
  1478. <li><i>contain</i></li>
  1479. <li><i>fill</i></li>
  1480. </ul>
  1481. </li>
  1482. <li><i>img_align</i> - '.__("brand image align to name:", 'brands-for-woocommerce').'
  1483. <ul>
  1484. <li><i>left</i> - '.__("image left to name", 'brands-for-woocommerce').'</li>
  1485. <li><i>right</i> - '.__("image right to name", 'brands-for-woocommerce').'</li>
  1486. <li><i>under</i> - '.__("image under name", 'brands-for-woocommerce').'</li>
  1487. <li><i>above</i> - '.__("image above name (default)", 'brands-for-woocommerce').'</li>
  1488. </ul>
  1489. </li>
  1490. <li><i>hierarchy</i> - '.__("brand image align to name:", 'brands-for-woocommerce') . '
  1491. <ul>
  1492. <li><i>top</i> - ' . __( 'Only top level', 'brands-for-woocommerce' ) . '</li>
  1493. <li><i>children</i> - ' . __( 'Only children (without hierarchy)', 'brands-for-woocommerce' ) . '</li>
  1494. <li><i>expand</i> - ' . __( 'Show full hierarchy', 'brands-for-woocommerce' ) . '</li>
  1495. <li><i>by_click</i> - ' . __( 'Expand by click', 'brands-for-woocommerce' ) . '</li>
  1496. <li><i>all</i> - ' . __( 'All brands without hierarchy (default)', 'brands-for-woocommerce' ) . '</li>
  1497. </ul>
  1498. </li>
  1499. <li><i>featured_first</i> - '.__("show featured brands first (0 or 1)", 'brands-for-woocommerce').'</li>
  1500. <li><i>include</i> - '.__("brands to display (id list, i.e. include='45,47,52,61')", 'brands-for-woocommerce').'</li>
  1501. <li><i>exclude</i> - '.__("brands to exclude from display (i.e. exclude='45,47,52,61')", 'brands-for-woocommerce').'</li>
  1502. </ul>
  1503. </li>
  1504. <li>
  1505. <span class="br_shortcode_title">
  1506. <strong><i class="fas fa-caret-right"></i>&nbsp;[brands_products]</strong> - '.__("product list for given brands (by ids or slugs)", 'brands-for-woocommerce').'
  1507. </span>
  1508. <ul class="br_shortcode_attributes">
  1509. <li><i>brand_id</i> - '.__("one or more brand ID (example: brand_id='12,34,35')", 'brands-for-woocommerce').'</li>
  1510. <li><i>brand_slug</i> - '.__("one or more brand slugs (example: brand_slug='brand1,brand2,brand3')", 'brands-for-woocommerce').'</li>
  1511. <li><b>'.__("Use only one of these options: brand_id or brand_slug", 'brands-for-woocommerce').'</b></li>
  1512. <li><i>columns</i> - '.__("number of columns for product list (4 by default). May not work with some themes or plugins", 'brands-for-woocommerce').'</li>
  1513. <li><i>per_page</i> - '.__("number of products per page; if not set, all products are shown", 'brands-for-woocommerce').'</li>
  1514. <li><i>orderby</i> - '.__("order products by:", 'brands-for-woocommerce').'
  1515. <ul>
  1516. <li><i>title</i> - '.__("product title (default)", 'brands-for-woocommerce').'</li>
  1517. <li><i>name</i> - '.__("product name (post slug)", 'brands-for-woocommerce').'</li>
  1518. <li><i>date</i> - '.__("date of creation", 'brands-for-woocommerce').'</li>
  1519. <li><i>modified</i> - '.__("last modified date", 'brands-for-woocommerce').'</li>
  1520. <li><i>rand</i> - '.__("random order", 'brands-for-woocommerce').'</li>
  1521. </ul>
  1522. </li>
  1523. <li><i>order</i> - '.__("sorting order:", 'brands-for-woocommerce').'
  1524. <ul>
  1525. <li><i>asc</i> - '.__("ascending (default)", 'brands-for-woocommerce').'</li>
  1526. <li><i>desc</i> - '.__("descending", 'brands-for-woocommerce').'</li>
  1527. </ul>
  1528. </li>
  1529. <li><i>slider</i> - '.__("1 for slider mode", 'brands-for-woocommerce').'
  1530. <li><i>hide_brands</i> - '.__("1 to hide brands", 'brands-for-woocommerce').'
  1531. </ul>
  1532. </li>
  1533. <li>
  1534. <span class="br_shortcode_title">
  1535. <strong><i class="fas fa-caret-right"></i>&nbsp;[brands_info]</strong> - '.__("show information about brand", 'brands-for-woocommerce').'
  1536. </span>
  1537. <ul class="br_shortcode_attributes">
  1538. <li><i>id</i> - '.__("brand ID", 'brands-for-woocommerce').'</li>
  1539. <li><i>type</i> - '.__("what to show:", 'brands-for-woocommerce').'
  1540. <ul>
  1541. <li><i>name</i> - '.__("name", 'brands-for-woocommerce').'</li>
  1542. <li><i>banner</i> - '.__("banner", 'brands-for-woocommerce').'</li>
  1543. <li><i>image</i> - '.__("thumbnail", 'brands-for-woocommerce').'</li>
  1544. <li><i>description</i> - '.__("description", 'brands-for-woocommerce').'</li>
  1545. <li><i>link</i> - '.__("external link", 'brands-for-woocommerce').'</li>
  1546. <li><i>related</i> - '.__("related products", 'brands-for-woocommerce').'</li>
  1547. <li><i>all</i> - '.__("all brand options", 'brands-for-woocommerce').'</li>
  1548. <li><b>'.__("You can use multiple brand properties, separated by comma. Example: type='image,name'", 'brands-for-woocommerce').'</b></li>
  1549. </ul>
  1550. </li>
  1551. <li><i>banner</i> - '.__("brand banner options: width, height, fit, align:", 'brands-for-woocommerce') . '
  1552. <ul>
  1553. <li><i>width</i> - '.__("width in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1554. <li><i>height</i> - '.__("height in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1555. <li><i>fit</i> - '.__("fit:", 'brands-for-woocommerce').'
  1556. <ul>
  1557. <li><i>cover</i> - '.__("default", 'brands-for-woocommerce').'</li>
  1558. <li><i>contain</i></li>
  1559. <li><i>fill</i></li>
  1560. <li><i>none</i></li>
  1561. </ul>
  1562. </li>
  1563. <li><i>align</i> - '.__("align:", 'brands-for-woocommerce') . '
  1564. <ul>
  1565. <li><i>left</i> - '.__("left", 'brands-for-woocommerce').'</li>
  1566. <li><i>right</i> - '.__("right", 'brands-for-woocommerce').'</li>
  1567. <li><i>center</i> - '.__("center", 'brands-for-woocommerce').'</li>
  1568. </ul>
  1569. </li>
  1570. <li>
  1571. <b>' . __('Examples:', 'brands-for-woocommerce') . '</b><br/>
  1572. <b>' . __('banner="width:50%,height:50px,fit:contain,align:center"', 'brands-for-woocommerce') . '</b><br/>
  1573. <b>' . __('banner="width:50%,height:50px"', 'brands-for-woocommerce') . '</b>
  1574. </li>
  1575. </ul>
  1576. </li>
  1577. <li><i>image</i> - '.__("brand thumbnail options: width, height, fit, align:", 'brands-for-woocommerce').'
  1578. <ul>
  1579. <li><i>width</i> - '.__("width in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1580. <li><i>height</i> - '.__("height in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1581. <li><i>fit</i> - '.__("fit:", 'brands-for-woocommerce').'
  1582. <ul>
  1583. <li><i>cover</i> - '.__("default", 'brands-for-woocommerce').'</li>
  1584. <li><i>contain</i></li>
  1585. <li><i>fill</i></li>
  1586. <li><i>none</i></li>
  1587. </ul>
  1588. </li>
  1589. <li><i>align</i> - '.__("align:", 'brands-for-woocommerce') . '
  1590. <ul>
  1591. <li><i>left</i> - '.__("left to description", 'brands-for-woocommerce').'</li>
  1592. <li><i>right</i> - '.__("right to description", 'brands-for-woocommerce').'</li>
  1593. <li><i>none</i> - '.__("no align", 'brands-for-woocommerce').'</li>
  1594. </ul>
  1595. </li>
  1596. <li>
  1597. <b>' . __('Examples:', 'brands-for-woocommerce') . '</b><br/>
  1598. <b>' . __('image="width:50%,height:50px,fit:contain,align:right"', 'brands-for-woocommerce') . '</b><br/>
  1599. <b>' . __('image="width:50%,height:50px"', 'brands-for-woocommerce') . '</b>
  1600. </li>
  1601. </ul>
  1602. </li>
  1603. <li><i>related</i> - '.__("related products options: per_page, columns, orderby, order, slider, hide_brands:", 'brands-for-woocommerce') . '
  1604. <ul>
  1605. <li><i>per_page</i> - '.__("width in px or % (i.e. 50%, 100px; default is 100%)", 'brands-for-woocommerce').'</li>
  1606. <li>
  1607. <b>' . __('Examples:', 'brands-for-woocommerce') . '</b><br/>
  1608. <b>' . __('related="width:50%,height:50px,fit:contain,align:right"', 'brands-for-woocommerce') . '</b><br/>
  1609. <b>' . __('image="width:50%,height:50px"', 'brands-for-woocommerce') . '</b>
  1610. </li>
  1611. </ul>
  1612. </li>
  1613. <li><i>featured</i> - '.__("display last created featured brand (1 or 0); <b>if featured=1, id is ignored</b>", 'brands-for-woocommerce').'</li>
  1614. </ul>
  1615. </li>
  1616. <li>
  1617. <span class="br_shortcode_title">
  1618. <strong><i class="fas fa-caret-right"></i>&nbsp;[brands_product_thumbnail]</strong> - '.__("brand image for product page", 'brands-for-woocommerce').'
  1619. </span>
  1620. <ul class="br_shortcode_attributes">
  1621. <li><i>post_id</i> - '.__("product id", 'brands-for-woocommerce').'</li>
  1622. <li><i>width</i> - '.__("image width (default is 35%)", 'brands-for-woocommerce').'</li>
  1623. <li><i>height</i> - '.__("image height (optionally)", 'brands-for-woocommerce').'</li>
  1624. <li><i>position</i> - '.__("float style for element (default is right)", 'brands-for-woocommerce').'
  1625. <ul>
  1626. <li><i>right</i> - '.__("right to text (default)", 'brands-for-woocommerce').'</li>
  1627. <li><i>left</i> - '.__("left to text", 'brands-for-woocommerce').'</li>
  1628. </ul>
  1629. </li>
  1630. <li><i>image</i> - '.__("display brand image, if available (1 or 0, default is 1)", 'brands-for-woocommerce').'</li>
  1631. <li><i>url</i> - '.__("display image as link (1 or 0, default is 0)", 'brands-for-woocommerce').'</li>
  1632. </ul>
  1633. </li>
  1634. <li>
  1635. <span class="br_shortcode_title">
  1636. <strong><i class="fas fa-caret-right"></i>&nbsp;[product_brands_info]</strong> - '.__("single brand info for single product", 'brands-for-woocommerce').'
  1637. </span>
  1638. <ul class="br_shortcode_attributes">
  1639. <li><i>product_id</i> - '.__("product ID; on single product page can get it automatically", 'brands-for-woocommerce').'</li>
  1640. <li><i>type</i> - '.__("what to display (all by default):", 'brands-for-woocommerce').'
  1641. <ul>
  1642. <li><i>name</i> - '.__("brand name", 'brands-for-woocommerce').'</li>
  1643. <li><i>image</i> - '.__("brand thumbnail", 'brands-for-woocommerce').'</li>
  1644. <li><i>description</i> - '.__("brand description", 'brands-for-woocommerce').'</li>
  1645. </ul>
  1646. </li>
  1647. </ul>
  1648. </ul>
  1649. </td>';
  1650. return $html;
  1651. }
  1652. public function filter_type_array($filter_type_array) {
  1653. $filter_type_array[self::$taxonomy_name] = array(
  1654. 'name' => __('Brands', 'brands-for-woocommerce'),
  1655. 'sameas' => 'custom_taxonomy',
  1656. 'attribute' => self::$taxonomy_name,
  1657. );
  1658. return $filter_type_array;
  1659. }
  1660. public function menu_order_sub_order($new_sub_order) {
  1661. $new_sub_order[ 'br-product_brand' ][] = array(
  1662. "<span class='berocket_admin_menu_custom_post_submenu'>" . __( 'All Brands', 'brands-for-woocommerce' ) . "</span>",
  1663. 'edit_posts',
  1664. 'edit-tags.php?taxonomy=berocket_brand&post_type=product&menu=berocket_account',
  1665. 'Brands',
  1666. );
  1667. return $new_sub_order;
  1668. }
  1669. function select_menu($file) {
  1670. global $plugin_page, $submenu_file;
  1671. if( $submenu_file == htmlentities('edit-tags.php?taxonomy=berocket_brand&post_type=product') ) {
  1672. $plugin_page = 'berocket_account';
  1673. }
  1674. return $file;
  1675. }
  1676. function select_submenu($submenu_file) {
  1677. if( $submenu_file == htmlentities('edit-tags.php?taxonomy=berocket_brand&post_type=product') ) {
  1678. return 'edit-tags.php?taxonomy=berocket_brand&post_type=product&menu=berocket_account';
  1679. }
  1680. return $submenu_file;
  1681. }
  1682. function activation() {
  1683. parent::activation();
  1684. $this->register_taxonomy();
  1685. flush_rewrite_rules();
  1686. }
  1687. function options_to_update( $options ) {
  1688. $options = array(
  1689. '3.6' => array(
  1690. 'update_options' => array(
  1691. 'display_thumbnail' => 'thumbnail',
  1692. ),
  1693. 'width_options' => array(
  1694. 'thumbnail_width' => 'thumbnail_width',
  1695. ),
  1696. ),
  1697. // '3.7' => array(
  1698. // 'update_options' => array(
  1699. // 'thumbnail_display' => 'thumbnail',
  1700. // ),
  1701. // ),
  1702. );
  1703. return $options;
  1704. }
  1705. public function update_from_older() {
  1706. $version = get_option('BeRocket_Framework_plugins_version_check');
  1707. $brand_version = ( empty( $version ) || empty( $version['product_brand'] ) ) ? 0 : $version['product_brand'];
  1708. if ( version_compare( $brand_version, $this->info['version'], '>=' ) ) return;
  1709. $this->plugin_version_check();
  1710. $terms = get_terms( 'berocket_brand', array( 'hide_empty' => false ) );
  1711. $defaults = array_combine ( array_keys( $this->attributes ), array_column( $this->attributes, 'default' ) );
  1712. foreach ( $terms as $term ) {
  1713. $term_meta = get_term_meta( $term->term_id );
  1714. foreach ( $defaults as $key => $default_value ) {
  1715. if ( empty( $term_meta[$key] ) ) {
  1716. update_term_meta( $term->term_id, $key, $default_value );
  1717. }
  1718. }
  1719. }
  1720. $options = $this->get_option();
  1721. if ( version_compare($brand_version, '3.0.1', '<') ) {
  1722. $version_index = 1;
  1723. } else {
  1724. $version_index = 2;
  1725. }
  1726. if( $version_index == 1 && ! empty($options['product_thumbnail']) ) {
  1727. $options['product_display_brand'] = '1';
  1728. $options['product_display_position'] = 'after_title';
  1729. $options['product_what_to_display_image'] = '1';
  1730. $options['product_display_image_width'] = '35%';
  1731. }
  1732. update_option( $this->values['settings_name'], $options );
  1733. }
  1734. function update_version( $previous, $current ) {
  1735. $options = $this->get_option();
  1736. $update_options = apply_filters( 'br_brands_options_to_update', array() );
  1737. $new_options = array();
  1738. if ( version_compare( $previous, '3.6', '<' ) ) {
  1739. $new_options += $update_options['3.6'];
  1740. }
  1741. // if ( version_compare( $previous, '3.7', '<' ) ) {
  1742. // $new_options += $update_options['3.7'];
  1743. // }
  1744. if ( !empty( $new_options['update_options'] ) ) {
  1745. foreach ( $new_options['update_options'] as $old_key => $new_key ) {
  1746. $options[$new_key] = empty( $options[$old_key] ) ? '' : $options[$old_key];
  1747. }
  1748. }
  1749. if ( !empty( $new_options['width_options'] ) ) {
  1750. foreach ( $new_options['width_options'] as $old_key => $new_key ) {
  1751. if ( empty( $options[$old_key] ) ) continue;
  1752. $new_width = intval( $options[$old_key] );
  1753. $units = str_replace( $new_width, '', $options[$old_key] );
  1754. $options[$new_key] = $new_width;
  1755. $options["{$new_key}_units"] = $units;
  1756. }
  1757. }
  1758. $options = apply_filters( 'br_brands_update_version', $options, $previous );
  1759. update_option( $this->values['settings_name'], $options );
  1760. wp_cache_delete( $this->values['settings_name'], 'berocket_framework_option' );
  1761. $this->clear_cache();
  1762. }
  1763. function wc_shortcode_atts($out, $pairs, $atts) {
  1764. if( ! empty($atts['brand']) ) {
  1765. $out['brand'] = $atts['brand'];
  1766. }
  1767. return $out;
  1768. }
  1769. function wc_shortcode_query($query_args, $atts = array()) {
  1770. if ( ! empty( $atts['brand'] ) ) {
  1771. $taxonomy = self::$taxonomy_name;
  1772. $terms = array_map( 'sanitize_title', explode( ',', $atts['brand'] ) );
  1773. $field = 'slug';
  1774. if ( $terms && is_numeric( $terms[0] ) ) {
  1775. $field = 'term_id';
  1776. $terms = array_map( 'absint', $terms );
  1777. // Check numeric slugs.
  1778. foreach ( $terms as $term ) {
  1779. $the_term = get_term_by( 'slug', $term, $taxonomy );
  1780. if ( false !== $the_term ) {
  1781. $terms[] = $the_term->term_id;
  1782. }
  1783. }
  1784. }
  1785. if( ! empty($terms) ) {
  1786. $query_args['tax_query'][] = array(
  1787. 'taxonomy' => $taxonomy,
  1788. 'terms' => $terms,
  1789. 'field' => $field,
  1790. 'operator' => $atts['terms_operator'],
  1791. );
  1792. }
  1793. }
  1794. return $query_args;
  1795. }
  1796. public static function get_tooltip( $term_id ) {
  1797. $tooltip = get_term_meta ( $term_id, 'br_brand_tooltip', true );
  1798. return self::get_tooltip_data( $tooltip );
  1799. }
  1800. public static function get_tooltip_data( $tooltip ) {
  1801. if( is_array( $tooltip ) ) return $tooltip;
  1802. return empty( $tooltip ) ? array( 'class' => '', 'data' => '' )
  1803. : array( 'class' => 'br_brand_tippy', 'data' => "data-tippy='$tooltip'" );
  1804. }
  1805. public function get_cache_key() {
  1806. global $berocket_unique_value;
  1807. $berocket_unique_value++;
  1808. $post_id = get_the_ID();
  1809. $language = '';
  1810. if( function_exists( 'qtranxf_getLanguage' ) ) {
  1811. $language = qtranxf_getLanguage();
  1812. }
  1813. if( defined('ICL_LANGUAGE_CODE') ) {
  1814. $language = ICL_LANGUAGE_CODE;
  1815. }
  1816. if( ! empty($language) ) {
  1817. $language = "_{$language}";
  1818. }
  1819. return "{$this->cache_key}_{$post_id}_{$berocket_unique_value}{$language}";
  1820. }
  1821. public function get_from_cache( $key ) {
  1822. $options = $this->get_option();
  1823. if ( empty( $options['use_cache'] ) ) return array();
  1824. return get_transient( $key );
  1825. }
  1826. public function set_to_cache( $key, $terms ) {
  1827. set_transient( $key, $terms, $this->cache_time );
  1828. $cache_list = get_transient( $this->cache_list );
  1829. if ( is_array( $cache_list ) ) {
  1830. $cache_list[] = $key;
  1831. } else {
  1832. $cache_list = array( $key );
  1833. }
  1834. set_transient( $this->cache_list, $cache_list, $this->cache_time );
  1835. }
  1836. public function save_order() {
  1837. $term_id = intval( sanitize_text_field( $_REQUEST['term_id'] ) );
  1838. $order = intval( sanitize_text_field( $_REQUEST['order'] ) );
  1839. update_term_meta( $term_id, 'br_brand_order', $order );
  1840. $this->clear_cache();
  1841. wp_die();
  1842. }
  1843. public function save_all_orders() {
  1844. foreach ( $_REQUEST['term_ids'] as $order => $term_id ) {
  1845. $term_id = intval( str_replace( 'tag-', '', $term_id ) );
  1846. update_term_meta( $term_id, 'br_brand_order', $order );
  1847. }
  1848. $this->clear_cache();
  1849. wp_die();
  1850. }
  1851. public function clear_cache( $needle = '' ) {
  1852. $cache_list = get_transient( $this->cache_list );
  1853. if ( empty( $cache_list ) || !is_array( $cache_list ) ) return;
  1854. foreach ( $cache_list as $cache_key ) {
  1855. if ( empty( $needle ) || strpos( $cache_key, $needle ) !== false ) {
  1856. delete_transient( $cache_key );
  1857. }
  1858. }
  1859. }
  1860. public function clear_cache_ajax() {
  1861. $this->clear_cache();
  1862. wp_die();
  1863. }
  1864. public function br_get_brands() {
  1865. $brands = json_encode( array_column( get_terms( BeRocket_product_brand::$taxonomy_name, array( 'hide_empty' => false, 'per_page' => -1 ) ), 'name' ) );
  1866. echo $brands;
  1867. wp_die();
  1868. }
  1869. public function woocommerce_duplicate_product( $new_id, $post ) {
  1870. $brands = get_the_terms($post->ID, self::$taxonomy_name );
  1871. if ( empty($brands) ) return;
  1872. $brands_id = wp_list_pluck( $brands, 'term_id' );
  1873. wp_set_post_terms( $new_id, $brands_id, self::$taxonomy_name );
  1874. }
  1875. public function brand_product_export_column_names( $columns ) {
  1876. $columns[ self::$taxonomy_name ] = __( 'Brands', 'brands-for-woocommerce' );
  1877. return $columns;
  1878. }
  1879. public function brand_export_product_column_brand_taxonomy( $value, $product ) {
  1880. $terms = get_terms( array( 'object_ids' => $product->get_ID(), 'taxonomy' => self::$taxonomy_name ) );
  1881. if ( is_wp_error( $terms ) ) return $value;
  1882. return implode( ', ', wp_list_pluck( $terms, 'name' ) );
  1883. }
  1884. public function brand_product_import_mapping_default_columns( $columns ) {
  1885. $columns[ __( 'Brands', 'brands-for-woocommerce' ) ] = self::$taxonomy_name;
  1886. $columns[ 'Brands' ] = self::$taxonomy_name; // Always add English mappings.
  1887. return $columns;
  1888. }
  1889. public function brand_product_importer_parsed_data( $parsed_data, $importer ) {
  1890. if ( empty( $parsed_data[ self::$taxonomy_name ] ) ) return $parsed_data;
  1891. $parsed_data[ self::$taxonomy_name ] = explode( ', ', $parsed_data[ self::$taxonomy_name ] );
  1892. return $parsed_data;
  1893. }
  1894. public function brand_product_import_inserted_product_object( $product, $data ) {
  1895. if ( !is_a( $product, 'WC_Product' ) || empty( $data[ self::$taxonomy_name ] ) ) return $product;
  1896. $object_terms = wp_set_object_terms( $product->get_id(), (array) $data[ self::$taxonomy_name ], self::$taxonomy_name );
  1897. return $product;
  1898. }
  1899. public function remove_brand_crumb( $crumbs, $breadcrumb ) {
  1900. $new_crumbs = array();
  1901. if ( !is_tax( self::$taxonomy_name ) ) return $crumbs;
  1902. foreach ( $crumbs as $key => $crumb ) {
  1903. if ( $crumb[0] !== __( 'Brands', 'brands-for-woocommerce' ) ) {
  1904. $new_crumbs[] = $crumb;
  1905. }
  1906. }
  1907. return $new_crumbs;
  1908. }
  1909. }
  1910. new BeRocket_product_brand;