Genesis Connect for WooCommerce - Version 1.0.0

Version Description

Download this release

Release Info

Developer studiopress
Plugin Icon 128x128 Genesis Connect for WooCommerce
Version 1.0.0
Comparing to
See all releases

Code changes from version 0.9.10 to 1.0.0

admin/notices.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Callbacks for `admin_notices` action to load HTML notices.
4
+ *
5
+ * @package genesis_connect_woocommerce
6
+ * @version 1.0
7
+ */
8
+ defined( 'ABSPATH' ) || exit;
9
+
10
+ function gencwooc_woocommerce_notice() {
11
+ include GCW_ADMIN_DIR . '/views/html-notice-needs-woocommerce.php';
12
+ }
13
+
14
+ function gencwooc_genesis_notice() {
15
+ include GCW_ADMIN_DIR . '/views/html-notice-needs-genesis.php';
16
+ }
admin/views/html-notice-needs-genesis.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Notice - needs Genesis.
4
+ */
5
+
6
+ defined( 'ABSPATH' ) || exit;
7
+
8
+ ?>
9
+ <div id="message" class="error notice">
10
+ <p><?php _e( '<i>Genesis Connect for WooCommerce</i> requires a Genesis child theme. <strong>Please activate a Genesis theme or disable Genesis Connect.</strong>', 'gencwooc' ); ?></p>
11
+ </div>
admin/views/html-notice-needs-woocommerce.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Notice - needs WooCommerce.
4
+ */
5
+
6
+ defined( 'ABSPATH' ) || exit;
7
+
8
+ ?>
9
+ <div id="message" class="error notice">
10
+ <p><?php _e( '<i>Genesis Connect for WooCommerce</i> requires WooCommerce. <strong>Please activate WooCommerce or disable Genesis Connect.</strong>', 'gencwooc' ); ?></p>
11
+ </div>
genesis-connect-woocommerce.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
2
  /*
3
  Plugin Name: Genesis Connect for WooCommerce
4
- Plugin URI: http://www.studiopress.com/plugins/genesis-connect-woocommerce
5
- Version: 0.9.10
6
  Author: StudioPress
7
- Author URI: http://www.studiopress.com/
8
  Description: Allows you to seamlessly integrate WooCommerce with the Genesis Framework and Genesis child themes.
 
 
9
 
10
  License: GNU General Public License v2.0 (or later)
11
  License URI: http://www.opensource.org/licenses/gpl-license.php
@@ -13,38 +15,13 @@ License URI: http://www.opensource.org/licenses/gpl-license.php
13
  Special thanks to Ade Walker (http://www.studiograsshopper.ch/) for his contributions to this plugin.
14
  */
15
 
16
-
17
- register_activation_hook( __FILE__, 'gencwooc_activation' );
18
- /**
19
- * Check the environment when plugin is activated
20
- *
21
- * Requirements:
22
- * - WooCommerce needs to be installed and activated
23
- *
24
- * Note: register_activation_hook() isn't run after auto or manual upgrade, only on activation
25
- * Note: this version of GCW is based on WooCommerce 2.1+
26
- *
27
- * @since 0.9.0
28
- */
29
- function gencwooc_activation() {
30
-
31
- //* If Genesis is not the active theme, deactivate and die.
32
- if ( 'genesis' != get_option( 'template' ) ) {
33
- deactivate_plugins( plugin_basename( __FILE__ ) );
34
- wp_die( sprintf( __( 'Sorry, you can\'t activate unless you have installed <a href="%s">Genesis</a>', 'gencwooc' ), 'http://my.studiopress.com/themes/genesis/' ) );
35
- }
36
-
37
- }
38
-
39
-
40
-
41
  /** Define the Genesis Connect for WooCommerce constants */
42
  define( 'GCW_TEMPLATE_DIR', dirname( __FILE__ ) . '/templates' );
43
  define( 'GCW_LIB_DIR', dirname( __FILE__ ) . '/lib');
 
 
44
  define( 'GCW_SP_DIR', dirname( __FILE__ ) . '/sp-plugins-integration' );
45
 
46
-
47
-
48
  add_action( 'after_setup_theme', 'gencwooc_setup' );
49
  /**
50
  * Setup GCW
@@ -57,11 +34,29 @@ add_action( 'after_setup_theme', 'gencwooc_setup' );
57
  */
58
  function gencwooc_setup() {
59
 
60
- /** Fail silently if WooCommerce is not activated */
61
- if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
62
- return;
 
 
 
63
 
64
- /** Environment is OK, let's go! */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  global $woocommerce;
67
 
@@ -78,22 +73,29 @@ function gencwooc_setup() {
78
  /** Ensure WooCommerce 2.0+ compatibility */
79
  add_theme_support( 'woocommerce' );
80
 
81
- /** Add Genesis Layout and SEO options to Product edit screen */
82
- add_post_type_support( 'product', array( 'genesis-layouts', 'genesis-seo' ) );
83
 
84
  /** Add Studiopress plugins support */
85
  add_post_type_support( 'product', array( 'genesis-simple-sidebars', 'genesis-simple-menus' ) );
86
 
 
 
 
 
 
87
  /** Take control of shop template loading */
88
  remove_filter( 'template_include', array( &$woocommerce, 'template_loader' ) );
89
  add_filter( 'template_include', 'gencwooc_template_loader', 20 );
90
 
91
  /** Integration - Genesis Simple Sidebars */
92
- if ( in_array( 'genesis-simple-sidebars/plugin.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
93
  require_once( GCW_SP_DIR . '/genesis-simple-sidebars.php' );
 
94
 
95
  /** Integration - Genesis Simple Menus */
96
- if ( in_array( 'genesis-simple-menus/simple-menu.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
97
  require_once( GCW_SP_DIR . '/genesis-simple-menus.php' );
 
98
 
99
  }
1
  <?php
2
  /*
3
  Plugin Name: Genesis Connect for WooCommerce
4
+ Plugin URI: https://wordpress.org/plugins/genesis-connect-woocommerce/
5
+ Version: 1.0
6
  Author: StudioPress
7
+ Author URI: https://www.studiopress.com/
8
  Description: Allows you to seamlessly integrate WooCommerce with the Genesis Framework and Genesis child themes.
9
+ WC requires at least: 3.3.0
10
+ WC tested up to: 3.4
11
 
12
  License: GNU General Public License v2.0 (or later)
13
  License URI: http://www.opensource.org/licenses/gpl-license.php
15
  Special thanks to Ade Walker (http://www.studiograsshopper.ch/) for his contributions to this plugin.
16
  */
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /** Define the Genesis Connect for WooCommerce constants */
19
  define( 'GCW_TEMPLATE_DIR', dirname( __FILE__ ) . '/templates' );
20
  define( 'GCW_LIB_DIR', dirname( __FILE__ ) . '/lib');
21
+ define( 'GCW_ADMIN_DIR', dirname( __FILE__ ) . '/admin');
22
+ define( 'GCW_WIDGETS_DIR', dirname( __FILE__ ) . '/widgets' );
23
  define( 'GCW_SP_DIR', dirname( __FILE__ ) . '/sp-plugins-integration' );
24
 
 
 
25
  add_action( 'after_setup_theme', 'gencwooc_setup' );
26
  /**
27
  * Setup GCW
34
  */
35
  function gencwooc_setup() {
36
 
37
+ require_once GCW_ADMIN_DIR . '/notices.php';
38
+ $ready = true;
39
+
40
+ if ( ! function_exists( 'is_plugin_active' ) ) {
41
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
42
+ }
43
 
44
+ if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
45
+ add_action( 'admin_notices', 'gencwooc_woocommerce_notice' );
46
+ $ready = false;
47
+ }
48
+
49
+ if ( ! function_exists( 'genesis' ) ) {
50
+ if ( ! is_multisite() ) {
51
+ add_action( 'admin_notices', 'gencwooc_genesis_notice' );
52
+ }
53
+
54
+ $ready = false;
55
+ }
56
+
57
+ if ( ! $ready ) {
58
+ return;
59
+ }
60
 
61
  global $woocommerce;
62
 
73
  /** Ensure WooCommerce 2.0+ compatibility */
74
  add_theme_support( 'woocommerce' );
75
 
76
+ /** Add Genesis Layout, Genesis Scripts and SEO options to Product edit screen */
77
+ add_post_type_support( 'product', array( 'genesis-layouts', 'genesis-scripts', 'genesis-seo' ) );
78
 
79
  /** Add Studiopress plugins support */
80
  add_post_type_support( 'product', array( 'genesis-simple-sidebars', 'genesis-simple-menus' ) );
81
 
82
+ /** Add Widgets */
83
+ if ( current_theme_supports( 'gencwooc-featured-products-widget' ) ) {
84
+ require_once( GCW_WIDGETS_DIR . '/woocommerce-featured-widgets.php' );
85
+ }
86
+
87
  /** Take control of shop template loading */
88
  remove_filter( 'template_include', array( &$woocommerce, 'template_loader' ) );
89
  add_filter( 'template_include', 'gencwooc_template_loader', 20 );
90
 
91
  /** Integration - Genesis Simple Sidebars */
92
+ if ( is_plugin_active( 'genesis-simple-sidebars/plugin.php' ) ) {
93
  require_once( GCW_SP_DIR . '/genesis-simple-sidebars.php' );
94
+ }
95
 
96
  /** Integration - Genesis Simple Menus */
97
+ if ( is_plugin_active( 'genesis-simple-menus/simple-menu.php' ) ) {
98
  require_once( GCW_SP_DIR . '/genesis-simple-menus.php' );
99
+ }
100
 
101
  }
lib/template-loader.php CHANGED
@@ -54,6 +54,9 @@ if ( ! defined( 'ABSPATH' ) )
54
  */
55
  function gencwooc_template_loader( $template ) {
56
 
 
 
 
57
 
58
  if ( is_single() && 'product' == get_post_type() ) {
59
 
@@ -63,7 +66,7 @@ function gencwooc_template_loader( $template ) {
63
  $template = GCW_TEMPLATE_DIR . '/single-product.php';
64
 
65
  }
66
- elseif ( is_post_type_archive( 'product' ) || is_page( get_option( 'woocommerce_shop_page_id' ) ) ) {
67
 
68
  $template = locate_template( array( 'woocommerce/archive-product.php' ) );
69
 
54
  */
55
  function gencwooc_template_loader( $template ) {
56
 
57
+ if ( class_exists( 'WC_Embed' ) && WC_Embed::is_embedded_product() ) {
58
+ return $template;
59
+ }
60
 
61
  if ( is_single() && 'product' == get_post_type() ) {
62
 
66
  $template = GCW_TEMPLATE_DIR . '/single-product.php';
67
 
68
  }
69
+ elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
70
 
71
  $template = locate_template( array( 'woocommerce/archive-product.php' ) );
72
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Plugin Name ===
2
- Contributors: nathanrice, studiopress, studiograsshopper
3
  Tags: genesis, genesiswp, studiopress, woocommerce
4
  Requires at least: 3.3
5
- Tested up to: 4.7
6
- Stable tag: 0.9.10
7
 
8
  This plugin allows you to seamlessly integrate WooCommerce with the Genesis Framework and Genesis child themes.
9
 
@@ -15,7 +15,7 @@ To allow easy customization of these templates, and ensure that you do not lose
15
 
16
  Additionally, the plugin makes [Genesis Simple Sidebars](http://wordpress.org/extend/plugins/genesis-simple-sidebars/) and [Genesis Simple Menus](http://wordpress.org/extend/plugins/genesis-simple-menus/) compatible with WooCommerce.
17
 
18
- **This version is compatible with WooCommerce 3.0+**
19
 
20
  == Installation ==
21
 
@@ -52,10 +52,6 @@ There's no need! Genesis Connect for WooCommerce modifies the default Genesis br
52
 
53
  Yes.
54
 
55
- = Does it work with Genesis Simple Sidebars? =
56
-
57
- Yes.
58
-
59
  = How does the plugin handle WooCommerce's CSS? =
60
 
61
  Genesis Connect for WooCommerce does not modify WooCommerce's way of working with CSS. By default, WooCommerce provides its own `woocommerce.css` file containing basic styles for the shop pages which is located here: `wp-content/plugins/woocommerce/assets/css/woocommerce.css`.
@@ -135,6 +131,24 @@ For the benefit of theme developers and customizers, here is a summary of possib
135
 
136
  == Changelog ==
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  = 0.9.10 =
139
  * Update theme templates for WooCommerce 3.3
140
  * Add Featured Products Widget
1
  === Plugin Name ===
2
+ Contributors: nathanrice, studiopress, studiograsshopper, modernnerd, marksabbath, calvinkoepke, curtismchale
3
  Tags: genesis, genesiswp, studiopress, woocommerce
4
  Requires at least: 3.3
5
+ Tested up to: 4.9
6
+ Stable tag: 1.0
7
 
8
  This plugin allows you to seamlessly integrate WooCommerce with the Genesis Framework and Genesis child themes.
9
 
15
 
16
  Additionally, the plugin makes [Genesis Simple Sidebars](http://wordpress.org/extend/plugins/genesis-simple-sidebars/) and [Genesis Simple Menus](http://wordpress.org/extend/plugins/genesis-simple-menus/) compatible with WooCommerce.
17
 
18
+ **This version is compatible with WooCommerce 3.3+**
19
 
20
  == Installation ==
21
 
52
 
53
  Yes.
54
 
 
 
 
 
55
  = How does the plugin handle WooCommerce's CSS? =
56
 
57
  Genesis Connect for WooCommerce does not modify WooCommerce's way of working with CSS. By default, WooCommerce provides its own `woocommerce.css` file containing basic styles for the shop pages which is located here: `wp-content/plugins/woocommerce/assets/css/woocommerce.css`.
131
 
132
  == Changelog ==
133
 
134
+ = 1.0 =
135
+ * Released 7 August 2018.
136
+ * Add WooCommerce version check support.
137
+ * Reinstate Genesis Featured Products widget. (Enable with `add_theme_support( 'gencwooc-featured-products-widget' );`.)
138
+ * Prevent ‘ID was called incorrectly’ error if Genesis Featured Products widget is in use.
139
+ * Remove product Microdata to prevent conflict with JSON-LD from WooCommerce 3.
140
+ * Prevent deprecation notice if Genesis Simple Sidebars is in use.
141
+ * The Genesis Featured Products widget now hides products with a price or sale price of '0' if ‘hide free products’ is ticked.
142
+ * Prevent blank pages if WooCommerce Shop page is not set. (Thanks, Tim Jensen!)
143
+ * Prevent fatal error on WooCommerce pages if non-Genesis theme or mobile plugin such as WPtouch is active.
144
+ * Add support for Genesis Scripts to products. (Thanks, Graham Washbrook!)
145
+ * The shop page now uses the default site layout if “Default Layout set in Theme Settings” is selected.
146
+ * Show a notice instead of dying if WooCommerce is not active.
147
+ * Show a notice instead of failing silently if a Genesis child theme is not active.
148
+ * Use the default template for product oembeds.
149
+ * Show the Genesis archive headline and intro text on product taxonomy archives if set. Fall back to the archive name and description.
150
+ * Allow network activation on WordPress multisite networks.
151
+
152
  = 0.9.10 =
153
  * Update theme templates for WooCommerce 3.3
154
  * Add Featured Products Widget
sp-plugins-integration/genesis-simple-sidebars.php CHANGED
@@ -76,8 +76,8 @@ function gencwooc_ss_handler() {
76
  * Checks if we're on the product archive and a GSS sidebar has been
77
  * assigned in the Shop WP Page editor, then, if both true, loads the relevant
78
  * GSS sidebar on the Shop Page.
79
- * If either of the above conditions return false, we hand back control to GSS
80
- * by executing the normal ss_do_one_sidebar() function.
81
  *
82
  * @since 0.9.0
83
  *
@@ -95,11 +95,10 @@ function gencwooc_ss_do_sidebar() {
95
 
96
  } else {
97
 
98
- /** Hand back control to GSS */
99
- if ( ! ss_do_one_sidebar( $bar ) )
100
- genesis_do_sidebar();
101
 
102
  }
 
103
  }
104
 
105
 
@@ -113,8 +112,8 @@ function gencwooc_ss_do_sidebar() {
113
  * Checks if we're on the product archive and a GSS sidebar has been
114
  * assigned in the Shop WP Page editor, then, if both true, loads the relevant
115
  * GSS sidebar on the Shop Page.
116
- * If either of the above conditions return false, we hand back control to GSS
117
- * by executing the normal ss_do_one_sidebar_alt() function.
118
  *
119
  * @since 0.9.0
120
  *
@@ -127,13 +126,13 @@ function gencwooc_ss_do_sidebar_alt() {
127
  $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
128
 
129
  if ( is_post_type_archive( 'product' ) && $_bar = get_post_meta( $shop_id, $bar, true ) ) {
 
130
  dynamic_sidebar( $_bar );
131
 
132
  } else {
133
 
134
- /** Hand back control to GSS */
135
- if ( ! ss_do_one_sidebar( $bar ) )
136
- genesis_do_sidebar_alt();
137
 
138
  }
 
139
  }
76
  * Checks if we're on the product archive and a GSS sidebar has been
77
  * assigned in the Shop WP Page editor, then, if both true, loads the relevant
78
  * GSS sidebar on the Shop Page.
79
+ *
80
+ * If either of the above conditions return false, we load the regular sidebar.
81
  *
82
  * @since 0.9.0
83
  *
95
 
96
  } else {
97
 
98
+ genesis_do_sidebar();
 
 
99
 
100
  }
101
+
102
  }
103
 
104
 
112
  * Checks if we're on the product archive and a GSS sidebar has been
113
  * assigned in the Shop WP Page editor, then, if both true, loads the relevant
114
  * GSS sidebar on the Shop Page.
115
+ *
116
+ * If either of the above conditions return false, we load the regular alt sidebar.
117
  *
118
  * @since 0.9.0
119
  *
126
  $shop_id = function_exists( 'wc_get_page_id' ) ? wc_get_page_id( 'shop' ) : woocommerce_get_page_id( 'shop' );
127
 
128
  if ( is_post_type_archive( 'product' ) && $_bar = get_post_meta( $shop_id, $bar, true ) ) {
129
+
130
  dynamic_sidebar( $_bar );
131
 
132
  } else {
133
 
134
+ genesis_do_sidebar_alt();
 
 
135
 
136
  }
137
+
138
  }
templates/archive-product.php CHANGED
@@ -33,32 +33,26 @@ remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 )
33
  remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
34
  remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
35
 
36
-
37
- /** Get Shop Page ID */
38
- // @TODO Retained for backwards compatibility with < 1.6.0 WooC installs
39
- global $shop_page_id;
40
- $shop_page_id = get_option( 'woocommerce_shop_page_id' );
41
-
42
-
43
  add_filter( 'genesis_pre_get_option_site_layout', 'genesiswooc_archive_layout' );
44
  /**
45
- * Manage page layout for the Product archive (Shop) page
46
  *
47
- * Set the layout in the Genesis layouts metabox in the Page Editor
48
  *
49
  * @since 0.9.0
50
  *
51
- * @param str $layout Genesis layout, eg 'content-sidebar', etc
52
- * @global string|int $shop_page_id The ID of the Shop WP Page
53
- * @return str $layout Shop Page layout from postmeta
54
  */
55
  function genesiswooc_archive_layout( $layout ) {
56
 
57
- global $shop_page_id;
58
 
59
- $layout = get_post_meta( $shop_page_id, '_genesis_layout', true );
 
 
60
 
61
- return $layout;
62
 
63
  }
64
 
33
  remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
34
  remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
35
 
 
 
 
 
 
 
 
36
  add_filter( 'genesis_pre_get_option_site_layout', 'genesiswooc_archive_layout' );
37
  /**
38
+ * Manage page layout for the Product archive (Shop) page.
39
  *
40
+ * Set the layout in the Genesis layouts metabox in the Page Editor.
41
  *
42
  * @since 0.9.0
43
  *
44
+ * @param str $layout Current Genesis page layout, such as 'content-sidebar'.
45
+ * @return str Page layout if set for the shop page, otherwise the default site layout.
 
46
  */
47
  function genesiswooc_archive_layout( $layout ) {
48
 
49
+ $post_layout = get_post_meta( wc_get_page_id( 'shop' ), '_genesis_layout', true );
50
 
51
+ if ( ! $post_layout || 'default_layout' === $post_layout ) {
52
+ return $layout;
53
+ }
54
 
55
+ return $post_layout;
56
 
57
  }
58
 
templates/single-product.php CHANGED
@@ -61,14 +61,14 @@ function gencwooc_single_product_loop() {
61
 
62
  <?php do_action('woocommerce_before_single_product'); ?>
63
 
64
- <div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
65
 
66
  <?php do_action( 'woocommerce_before_single_product_summary' ); ?>
67
 
68
  <div class="summary">
69
-
70
  <?php do_action( 'woocommerce_single_product_summary'); ?>
71
-
72
  </div>
73
 
74
  <?php do_action( 'woocommerce_after_single_product_summary' ); ?>
61
 
62
  <?php do_action('woocommerce_before_single_product'); ?>
63
 
64
+ <div id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
65
 
66
  <?php do_action( 'woocommerce_before_single_product_summary' ); ?>
67
 
68
  <div class="summary">
69
+
70
  <?php do_action( 'woocommerce_single_product_summary'); ?>
71
+
72
  </div>
73
 
74
  <?php do_action( 'woocommerce_after_single_product_summary' ); ?>
templates/taxonomy.php CHANGED
@@ -19,8 +19,29 @@
19
  /** Remove default Genesis loop */
20
  remove_action( 'genesis_loop', 'genesis_do_loop' );
21
 
22
- /** Remove Genesis archive title/description */
23
- remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  /** Remove WooCommerce breadcrumbs */
26
  remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
19
  /** Remove default Genesis loop */
20
  remove_action( 'genesis_loop', 'genesis_do_loop' );
21
 
22
+ // Remove the WooCommerce archive title and description.
23
+ add_filter( 'woocommerce_show_page_title', '__return_false' );
24
+ remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description' );
25
+
26
+ add_filter( 'genesis_term_intro_text_output', 'genesiswooc_term_intro_text_output' );
27
+ /**
28
+ * Fall back to the archive description if no intro text is set.
29
+ *
30
+ * @param string $intro_text The default Genesis archive intro text.
31
+ * @return string Archive intro text, or archive description if no intro text set.
32
+ *
33
+ * @since 1.0
34
+ */
35
+ function genesiswooc_term_intro_text_output( $intro_text ) {
36
+ $wp_archive_description = get_the_archive_description();
37
+
38
+ if ( ! $intro_text && $wp_archive_description ) {
39
+ return $wp_archive_description;
40
+ }
41
+
42
+ return $intro_text;
43
+ }
44
+
45
 
46
  /** Remove WooCommerce breadcrumbs */
47
  remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
widgets/woocommerce-featured-widgets.php ADDED
@@ -0,0 +1,506 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file contains a widget to display WooCommerce products in a Genesis - Featured Post format.
4
+ *
5
+ * @package genesis_connect_woocommerce
6
+ * @version 0.9.9
7
+ *
8
+ * @since 0.9.9
9
+ */
10
+
11
+ /**
12
+ * Genesis Featured Products widget for the Genesis Connect plugin.
13
+ *
14
+ * @since 1.0.0
15
+ *
16
+ * @package Canvas
17
+ */
18
+ class Gencwooc_Featured_Products extends WC_Widget {
19
+
20
+ /**
21
+ * Holds widget settings defaults, populated in constructor.
22
+ *
23
+ * @var array
24
+ */
25
+ protected $defaults;
26
+
27
+ /**
28
+ * Constructor. Set the default widget options and create widget.
29
+ *
30
+ * @since 0.1.8
31
+ */
32
+ public function __construct() {
33
+
34
+ // Retrieve a list of product categories.
35
+ add_action( 'admin_init', array( $this, 'set_featured_products' ) );
36
+
37
+ // Set the widget default settings.
38
+ $this->defaults = apply_filters( 'gencwooc_featured_products_defaults', array(
39
+ 'category' => '',
40
+ 'count' => 8,
41
+ 'offset' => 0,
42
+ 'show_type' => '',
43
+ 'orderby' => 'date',
44
+ 'order' => 'desc',
45
+ 'hide_free' => 0,
46
+ 'show_hidden' => 0,
47
+ 'show_image' => 1,
48
+ 'image_size' => 'thumbnail',
49
+ 'link_image' => 1,
50
+ 'show_title' => 1,
51
+ 'show_add_to_cart' => 1,
52
+ 'show_price' => 1,
53
+ 'more_from_category' => 0,
54
+ 'more_from_category_text' => __( 'More Products from this Category', 'gencwooc' ),
55
+ ));
56
+
57
+ $this->widget_cssclass = 'featured-content featuredproducts';
58
+ $this->widget_name = __( 'Genesis - Featured Products', 'gencwooc' );
59
+ $this->widget_description = __( 'Displays featured products with thumbnails', 'gencwooc' );
60
+ $this->widget_id = 'featured-products';
61
+ $this->settings = array(
62
+ 'title' => array(
63
+ 'type' => 'text',
64
+ 'std' => '',
65
+ 'label' => __( 'Title', 'gencwooc' ),
66
+ ),
67
+ 'product_cat' => array(
68
+ 'type' => 'select',
69
+ 'std' => esc_html( $this->defaults['category'] ),
70
+ 'label' => __( 'Product Category', 'gencwooc' ),
71
+ 'options' => array(),
72
+ ),
73
+ 'product_num' => array(
74
+ 'type' => 'number',
75
+ 'step' => 1,
76
+ 'min' => 1,
77
+ 'max' => '',
78
+ 'std' => absint( $this->defaults['count'] ),
79
+ 'label' => __( 'Products to Show', 'gencwooc' ),
80
+ ),
81
+ 'product_offset' => array(
82
+ 'type' => 'number',
83
+ 'step' => 1,
84
+ 'min' => 0,
85
+ 'max' => '',
86
+ 'std' => absint( $this->defaults['offset'] ),
87
+ 'label' => __( 'Product Offset', 'gencwooc' ),
88
+ ),
89
+ 'product_show' => array(
90
+ 'type' => 'select',
91
+ 'std' => esc_html( $this->defaults['show_type'] ),
92
+ 'label' => __( 'Show', 'gencwooc' ),
93
+ 'options' => array(
94
+ '' => __( 'All products', 'gencwooc' ),
95
+ 'featured' => __( 'Featured products', 'gencwooc' ),
96
+ 'onsale' => __( 'On-sale products', 'gencwooc' ),
97
+ ),
98
+ ),
99
+ 'orderby' => array(
100
+ 'type' => 'select',
101
+ 'std' => esc_html( $this->defaults['orderby'] ),
102
+ 'label' => __( 'Order by', 'gencwooc' ),
103
+ 'options' => array(
104
+ 'date' => __( 'Date', 'gencwooc' ),
105
+ 'price' => __( 'Price', 'gencwooc' ),
106
+ 'rand' => __( 'Random', 'gencwooc' ),
107
+ 'sales' => __( 'Sales', 'gencwooc' ),
108
+ ),
109
+ ),
110
+ 'order' => array(
111
+ 'type' => 'select',
112
+ 'std' => esc_html( $this->defaults['order'] ),
113
+ 'label' => _x( 'Order', 'Sorting Order', 'gencwooc' ),
114
+ 'options' => array(
115
+ 'asc' => __( 'ASC', 'gencwooc' ),
116
+ 'desc' => __( 'DESC', 'gencwooc' ),
117
+ ),
118
+ ),
119
+ 'hide_free' => array(
120
+ 'type' => 'checkbox',
121
+ 'std' => absint( $this->defaults['hide_free'] ),
122
+ 'label' => __( 'Hide Free Products', 'gencwooc' ),
123
+ ),
124
+ 'show_hidden' => array(
125
+ 'type' => 'checkbox',
126
+ 'std' => absint( $this->defaults['show_hidden'] ),
127
+ 'label' => __( 'Show Hidden Products', 'gensis' ),
128
+ ),
129
+ 'show_image' => array(
130
+ 'type' => 'checkbox',
131
+ 'std' => absint( $this->defaults['show_image'] ),
132
+ 'label' => __( 'Show Featured Image?', 'gencwooc' ),
133
+ ),
134
+ 'image_size' => array(
135
+ 'type' => 'select',
136
+ 'std' => esc_html( $this->defaults['image_size'] ),
137
+ 'label' => __( 'Image Size', 'gencwooc' ),
138
+ 'options' => $this->get_featured_image_sizes(),
139
+ ),
140
+ 'link_image' => array(
141
+ 'type' => 'checkbox',
142
+ 'std' => absint( $this->defaults['link_image'] ),
143
+ 'label' => __( 'Link Product Image?', 'gencwooc' ),
144
+ ),
145
+ 'show_title' => array(
146
+ 'type' => 'checkbox',
147
+ 'std' => absint( $this->defaults['show_title'] ),
148
+ 'label' => __( 'Show Title?', 'gencwooc' ),
149
+ ),
150
+ 'show_add_to_cart' => array(
151
+ 'type' => 'checkbox',
152
+ 'std' => absint( $this->defaults['show_add_to_cart'] ),
153
+ 'label' => __( 'Show Add to Cart Button?', 'gencwooc' ),
154
+ ),
155
+ 'show_price' => array(
156
+ 'type' => 'checkbox',
157
+ 'std' => absint( $this->defaults['show_price'] ),
158
+ 'label' => __( 'Show Price?', 'gencwooc' ),
159
+ ),
160
+ 'more_from_category' => array(
161
+ 'type' => 'checkbox',
162
+ 'std' => absint( $this->defaults['more_from_category'] ),
163
+ 'label' => __( 'Show Category Archive Link?', 'gencwooc' ),
164
+ ),
165
+ 'more_from_category_text' => array(
166
+ 'type' => 'text',
167
+ 'std' => esc_html( $this->defaults['more_from_category_text'] ),
168
+ 'label' => __( 'Link Text:', 'gencwooc' ),
169
+ ),
170
+ );
171
+
172
+ parent::__construct();
173
+
174
+ }
175
+
176
+ /**
177
+ * Callback on the `admin_init` action.
178
+ * Sets the product_cat options using get_featured_product_categories()
179
+ * after the product_cat taxonomy has been registered.
180
+ *
181
+ * @return void
182
+ */
183
+ public function set_featured_products() {
184
+
185
+ $this->settings['product_cat']['options'] = $this->get_featured_product_categories();
186
+
187
+ }
188
+
189
+ /**
190
+ * Function to retrieve the actual product categories as an assosiative
191
+ * array. Used to output a dropdown in the widget settings.
192
+ *
193
+ * @return array Associative array of product categories.
194
+ */
195
+ public function get_featured_product_categories() {
196
+
197
+ $cats = get_terms( 'product_cat' );
198
+ $options = array(
199
+ '' => __( 'All Categories', 'gencwooc' ),
200
+ );
201
+
202
+ if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) {
203
+ foreach( $cats as $cat ) {
204
+ $options[$cat->slug] = $cat->name;
205
+ }
206
+ }
207
+
208
+ return $options;
209
+
210
+ }
211
+
212
+ /**
213
+ * Function to retrieve an associative array containing all possible
214
+ * featured image sizes to be used.
215
+ *
216
+ * @return array Associative array containg possible image sizes and dimensions.
217
+ */
218
+ public function get_featured_image_sizes() {
219
+
220
+ $options = [];
221
+ $images = genesis_get_image_sizes();
222
+
223
+ foreach( $images as $size => $data ) {
224
+
225
+ $name = sprintf( '%s: %s x %s', $size, $data['width'], $data['height'] );
226
+ $options[ $size ] = $name;
227
+
228
+ }
229
+
230
+ return $options;
231
+
232
+ }
233
+
234
+ /**
235
+ * Main function to retrieve a WP_Query object with appropriate arguments passed in from the instance.
236
+ *
237
+ * @param array $instance Instance arguments to be used in the query.
238
+ * @return object New WP_Query object to be looped through.
239
+ */
240
+ public function get_featured_products( $args, $instance ) {
241
+ $cat = ! empty( $instance['product_cat'] ) ? sanitize_title( $instance['product_cat'] ) : $this->settings['product_cat']['std'];
242
+ $count = ! empty( $instance['product_num'] ) ? absint( $instance['product_num'] ) : $this->settings['product_num']['std'];
243
+ $offset = ! empty( $instance['product_offset'] ) ? absint( $instance['product_offset'] ) : $this->settings['product_offset']['std'];
244
+
245
+ $orderby = ! empty( $instance['orderby'] ) ? sanitize_title( $instance['orderby'] ) : $this->settings['orderby']['std'];
246
+ $order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std'];
247
+ $product_show = ! empty( $instance['product_show'] ) ? sanitize_title( $instance['product_show'] ) : $this->settings['product_show']['std'];
248
+ $product_visibility_term_ids = wc_get_product_visibility_term_ids();
249
+
250
+ $query_args = array(
251
+ 'post_type' => 'product',
252
+ 'cat' => $cat,
253
+ 'showposts' => $count,
254
+ 'offset' => $offset,
255
+ 'order' => $order,
256
+ 'tax_query' => array(
257
+ 'relation' => 'AND',
258
+ ),
259
+ );
260
+
261
+ switch ( $product_show ) {
262
+ case 'featured':
263
+ $query_args['tax_query'][] = array(
264
+ 'taxonomy' => 'product_visibility',
265
+ 'field' => 'term_taxonomy_id',
266
+ 'terms' => $product_visibility_term_ids['featured'],
267
+ );
268
+ break;
269
+ case 'onsale':
270
+ $product_ids_on_sale = wc_get_product_ids_on_sale();
271
+ $product_ids_on_sale[] = 0;
272
+ $query_args['post__in'] = $product_ids_on_sale;
273
+ break;
274
+ }
275
+
276
+ if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
277
+ $query_args['tax_query'] = array(
278
+ array(
279
+ 'taxonomy' => 'product_visibility',
280
+ 'field' => 'term_taxonomy_id',
281
+ 'terms' => $product_visibility_term_ids['outofstock'],
282
+ 'operator' => 'NOT IN',
283
+ ),
284
+ );
285
+ }
286
+
287
+ if ( empty( $instance['show_hidden'] ) ) {
288
+ $query_args['tax_query'][] = array(
289
+ 'taxonomy' => 'product_visibility',
290
+ 'field' => 'term_taxonomy_id',
291
+ 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'],
292
+ 'operator' => 'NOT IN',
293
+ );
294
+ $query_args['post_parent'] = 0;
295
+ }
296
+
297
+ if ( ! empty( $instance['hide_free'] ) ) {
298
+ // Meta query ensures price and sale price are not explicitly set
299
+ // to a zero-like string. Empty pricing fields do not count as
300
+ // a free product. WooCommerce shows no purchase buttons for those.
301
+ $query_args['meta_query'][] = array(
302
+ 'relation' => 'AND',
303
+ array(
304
+ 'key' => '_price',
305
+ 'value' => array( '0', '00', '000', '0000', '0.00', '0,00' ),
306
+ 'compare' => 'NOT IN',
307
+ ),
308
+ array(
309
+ 'key' => '_sale_price',
310
+ 'value' => array( '0', '00', '000', '0000', '0.00', '0,00' ),
311
+ 'compare' => 'NOT IN',
312
+ ),
313
+ );
314
+ }
315
+
316
+ switch ( $orderby ) {
317
+ case 'price':
318
+ $query_args['meta_key'] = '_price';
319
+ $query_args['orderby'] = 'meta_value_num';
320
+ break;
321
+ case 'rand':
322
+ $query_args['orderby'] = 'rand';
323
+ break;
324
+ case 'sales':
325
+ $query_args['meta_key'] = 'total_sales';
326
+ $query_args['orderby'] = 'meta_value_num';
327
+ break;
328
+ default:
329
+ $query_args['orderby'] = 'date';
330
+ }
331
+
332
+ return new WP_Query( apply_filters( 'genwoo_featured_products_widget_query_args', $query_args ) );
333
+ }
334
+
335
+ /**
336
+ * Echo the widget content.
337
+ *
338
+ * @since 0.9.9
339
+ *
340
+ * @global WP_Query $product Product (post) object.
341
+ *
342
+ * @param array $args Display arguments including `before_title`, `after_title`,
343
+ * `before_widget`, and `after_widget`.
344
+ * @param array $instance The settings for the particular instance of the widget.
345
+ */
346
+ public function widget( $args, $instance ) {
347
+
348
+ if ( $this->get_cached_widget( $args ) ) {
349
+ return;
350
+ }
351
+
352
+ ob_start();
353
+
354
+ $instance = wp_parse_args( $instance, $this->defaults );
355
+
356
+ if ( ( $products = $this->get_featured_products( $args, $instance ) ) && $products->have_posts() ) {
357
+ $this->widget_start( $args, $instance );
358
+
359
+ genesis_markup( array(
360
+ 'open' => '<ul %s>',
361
+ 'context' => 'featured-products-list',
362
+ ));
363
+
364
+ while ( $products->have_posts() ) {
365
+ $products->the_post();
366
+
367
+ global $product;
368
+
369
+ genesis_markup(array(
370
+ 'open' => '<li %s>',
371
+ 'context' => 'entry-product',
372
+ ));
373
+
374
+ $image = genesis_get_image( array(
375
+ 'format' => 'html',
376
+ 'size' => $instance['image_size'],
377
+ 'context' => 'featured-product-image',
378
+ 'attr' => genesis_parse_attr( 'featured-product-image', array ( 'alt' => get_the_title() ) ),
379
+ ) );
380
+
381
+ if ( $image && $instance['show_image'] ) {
382
+ if ( $instance['link_image'] ) {
383
+ printf( '<a href="%s" class="entry-image-wrap">%s</a>', get_permalink(), wp_make_content_images_responsive( $image ) );
384
+ } else {
385
+ printf( '<div class="entry-image-wrap">%s</div>', wp_make_content_images_responsive( $image ) );
386
+ }
387
+ }
388
+
389
+ if ( $instance['show_title'] ) {
390
+
391
+ $header = '';
392
+
393
+ if ( ! empty( $instance['show_title'] ) ) {
394
+
395
+ $title = get_the_title() ? get_the_title() : __( '(no title)', 'gencwooc' );
396
+
397
+ /**
398
+ * Filter the featured post widget title.
399
+ *
400
+ * @since 2.2.0
401
+ *
402
+ * @param string $title Featured post title.
403
+ * @param array $instance {
404
+ * Widget settings for this instance.
405
+ *
406
+ * @type string $title Widget title.
407
+ * @type int $product_cat ID of the post category.
408
+ * @type int $product_num Number of posts to show.
409
+ * @type int $product_offset Number of posts to skip when
410
+ * retrieving.
411
+ * @type string $orderby Field to order posts by.
412
+ * @type string $order ASC fr ascending order, DESC for
413
+ * descending order of posts.
414
+ * @type bool $show_image True if featured image should be
415
+ * shown, false otherwise.
416
+ * @type bool $show_hidden True if hidden products should be
417
+ * shown, false otherwise.
418
+ * @type string $image_size Name of the image size.
419
+ * @type bool $show_title True if featured page title should
420
+ * be shown, false otherwise.
421
+ * @type int $extra_num Number of extra post titles to show.
422
+ * @type string $extra_title Heading for extra posts.
423
+ * @type bool $more_from_category True if showing category archive
424
+ * link, false otherwise.
425
+ * @type string $more_from_category_text Category archive link text.
426
+ * }
427
+ * @param array $args {
428
+ * Widget display arguments.
429
+ *
430
+ * @type string $before_widget Markup or content to display before the widget.
431
+ * @type string $before_title Markup or content to display before the widget title.
432
+ * @type string $after_title Markup or content to display after the widget title.
433
+ * @type string $after_widget Markup or content to display after the widget.
434
+ * }
435
+ */
436
+ $title = apply_filters( 'genesis_featured_product_title', $title, $instance, $args );
437
+ $heading = genesis_a11y( 'headings' ) ? 'h4' : 'h2';
438
+
439
+ $header .= genesis_markup( array(
440
+ 'open' => "<{$heading} %s>",
441
+ 'close' => "</{$heading}>",
442
+ 'context' => 'entry-product-title',
443
+ 'content' => sprintf( '<a href="%s">%s</a>', get_permalink(), $title ),
444
+ 'echo' => false,
445
+ ) );
446
+
447
+ }
448
+
449
+ genesis_markup( array(
450
+ 'open' => '<header %s>',
451
+ 'close' => '</header>',
452
+ 'context' => 'entry-product-header',
453
+ 'content' => $header,
454
+ ));
455
+
456
+ }
457
+
458
+ if ( $instance['show_price'] && $product->get_price_html() ) {
459
+ printf( '<span class="price">%s</span>', $product->get_price_html() );
460
+ }
461
+
462
+ if ( $instance['show_add_to_cart'] ) {
463
+ woocommerce_template_loop_add_to_cart( $product->get_id() );
464
+ }
465
+
466
+ genesis_markup( array(
467
+ 'close' => '</li>',
468
+ 'context' => 'entry-product',
469
+ ));
470
+
471
+ }
472
+
473
+ genesis_markup( array(
474
+ 'close' => '</ul>',
475
+ 'context' => 'featured-products-list',
476
+ ));
477
+
478
+ if ( $instance['more_from_category'] && $instance['product_cat'] !== '' ) {
479
+
480
+ $cat = get_term_by( 'name', $instance['product_cat'], 'product_cat' );
481
+
482
+ printf(
483
+ '<p class="more-from-category"><a href="%1$s" title="%2$s">%3$s</a></p>',
484
+ esc_url( get_term_link( $cat->term_taxonomy_id ) ),
485
+ esc_attr( $cat->name ),
486
+ esc_html( $instance['more_from_category_text'] )
487
+ );
488
+ }
489
+
490
+ $this->widget_end( $args );
491
+
492
+ }
493
+
494
+ // Restore original query.
495
+ wp_reset_postdata();
496
+
497
+ echo $this->cache_widget( $args, ob_get_clean() );
498
+
499
+ }
500
+
501
+ }
502
+
503
+ add_action( 'widgets_init', 'gencwooc_register_featured_products_widget' );
504
+ function gencwooc_register_featured_products_widget() {
505
+ register_widget( 'Gencwooc_Featured_Products' );
506
+ }