Forked from drawcard/woocommerce-sage-template-part-overrides.md
Created
June 12, 2017 14:01
-
-
Save xavierartot/dc2f47bff8b27f5a48f2bcf1ff5fc0f0 to your computer and use it in GitHub Desktop.
Revisions
-
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -63,4 +63,4 @@ For Sage, you need to make your template part override here: /your-theme-root-folder/woocommerce/**single-product/product-image.php** (no /templates/ folder required!) ### Troubleshooting * If you are getting a blank page after copying and pasting code, then there is an error somewhere in your PHP code. Switch on [WP_DEBUG](https://codex.wordpress.org/WP_DEBUG) to investigate and check to see if you are using the template part for the specific version of WooCommerce you're using. Eg if you are on version 2.3.8 of WooCommerce, you need to be getting your template code from the 2.3.8 tree of the Github repo (or "master" if you're just using the latest stable release version.) -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -63,4 +63,4 @@ For Sage, you need to make your template part override here: /your-theme-root-folder/woocommerce/**single-product/product-image.php** (no /templates/ folder required!) ### Troubleshooting * If you are getting a blank page after copying and pasting code, check to see if you are using the template part for the specific version of WooCommerce you're using. Eg if you are on version 2.3.8 of WooCommerce, you need to be getting your template code from the 2.3.8 tree of the Github repo (or "master" if you're just using the latest stable release version.) -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,10 +11,10 @@ Now you're familiar with how to do Sage + Woocommerce templates, it's time to ma Let's say you want to override a part of a theme in the single product view, like adding some classes to the DIVs that surround the product image. * Create a Sage template for the entire page to be modified, using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```/your-theme-root-folder/single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly (It should report: ```Main: single-product.php Base: base.php (by default).```) ### The template part * Select a function within the that new file which you'd like to be customised, eg change the HTML code within the template part that the hook presents. For instance, here we want to modify the way images are presented, so we need to examine the ```woocommerce_show_product_images``` function within the ```woocommerce_before_single_product_summary``` hook. ```php <?php @@ -27,7 +27,7 @@ Let's say you want to override a part of a theme in the single product view, lik do_action( 'woocommerce_before_single_product_summary' ); // <---- the hook name ?> ``` * Look up the function in [WooCommerce Functions Reference](http://docs.woothemes.com/wc-apidocs/package-WooCommerce.Functions.html) and check out where the function is derived from, eg: ``` Function woocommerce_show_product_images @@ -37,7 +37,7 @@ Package: WooCommerce\Functions\Product Author: WooThemes Located at includes/wc-template-functions.php ``` * Click on that file reference, eg ```includes/wc-template-functions.php``` to find out what template part the function uses: ```php /** * Output the product image before the single product summary. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ Located at includes/wc-template-functions.php wc_get_template( 'single-product/product-image.php' ); //<---- the template part } ``` 5. Now we know what template part to override, we simply create that part of the template in Sage, copy and paste the code from the original [WooCommerce template part](https://github.com/woothemes/woocommerce/tree/master/templates) into our new file, and make whatever changes we want to. Use this example as a reference: ```php wc_get_template( 'single-product/product-image.php' ); -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Located at includes/wc-template-functions.php wc_get_template( 'single-product/product-image.php' ); ``` WooCommerce is expecting your overrides to be in: /your-theme-root-folder/woocommerce/**templates/single-product/product-image.php** For Sage, you need to make your template part override here: /your-theme-root-folder/woocommerce/**single-product/product-image.php** (no /templates/ folder required!) ### Troubleshooting * If you are getting a blank page after copying and pasting code, check to see if you are using the template part for the specific version of WooCommerce you're using. Eg if you are on version 2.3.8 of WooCommerce, you need to be getting your template code from the 2.3.8 tree of the Github repo. In the repo, click on the Branch / Tag dropdown and select Tags > 2.3.8 (or whatever version you're using). Then click "Raw" and copy the code. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,8 +59,8 @@ wc_get_template( 'single-product/product-image.php' ); WooCommerce is expecting your overrides to be in: **/your-theme-root-folder/woocommerce/templates/single-product/product-image.php** For Sage, you need to make your template part override here: **/your-theme-root-folder/woocommerce/single-product/product-image.php** (no /templates/ folder required!) ### Troubleshooting * If you are getting a blank page after copying and pasting code, check to see if you are using the template part for the specific version of WooCommerce you're using. Eg if you are on version 2.3.8 of WooCommerce, you need to be getting your template code from the 2.3.8 tree of the Github repo. In the repo, click on the Branch / Tag dropdown and select Tags > 2.3.8 (or whatever version you're using). Then click "Raw" and copy the code. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ So, you know how to override a template file in Woocommerce using Sage, but you're having trouble changing something within the deeper level of that template file. For example, you want to change the output HTML structure of a given part of the product page loop, or incorporate a Bootstrap class into a button element without using Jquery to inject it. Here's how you can override deeper level parts, the default WC theme elements. ### Prerequisites * Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ So, you know how to override a template file in Woocommerce using Sage, but you're having trouble changing something within the deeper level of that template file. For example, you want to change the output HTML structure of a given part of the product page loop, or incorporate a Bootstrap class into a button element without using Jquery to inject it. Here's how you can override deeper level parts of the theme. ### Prerequisites * Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin. * Also check out how to set up [Sage Templates & Woocommerce](https://roots.io/using-woocommerce-with-sage/) * Install [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to preserve your sanity! Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. @@ -58,4 +60,7 @@ wc_get_template( 'single-product/product-image.php' ); WooCommerce is expecting your overrides to be in: **/your-theme-root-folder/woocommerce/templates/single-product/product-image.php** You need to make your template part override here: **/your-theme-root-folder/woocommerce/single-product/product-image.php** ### Troubleshooting * If you are getting a blank page after copying and pasting code, check to see if you are using the template part for the specific version of WooCommerce you're using. Eg if you are on version 2.3.8 of WooCommerce, you need to be getting your template code from the 2.3.8 tree of the Github repo. In the repo, click on the Branch / Tag dropdown and select Tags > 2.3.8 (or whatever version you're using). Then click "Raw" and copy the code. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,5 +57,5 @@ wc_get_template( 'single-product/product-image.php' ); WooCommerce is expecting your overrides to be in: **/your-theme-root-folder/woocommerce/templates/single-product/product-image.php** You need to make your template part override here: **/your-theme-root-folder/woocommerce/single-product/product-image.php** -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,13 @@ So, you know how to override a template file in Woocommerce using Sage, but you' Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. ### The template page override Let's say you want to override a part of a theme in the single product view, like adding some classes to the DIVs that surround the product image. 1. Create a Sage template for the entire page to be modified, using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```/your-theme-root-folder/single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly (It should report: ```Main: single-product.php Base: base.php (by default).```) ### The template part 2. Select a function within the that new file which you'd like to be customised, eg change the HTML code within the template part that the hook presents. For instance, here we want to modify the way images are presented, so we need to examine the ```woocommerce_show_product_images``` function within the ```woocommerce_before_single_product_summary``` hook. ```php -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,13 @@ So, you know how to override a template file in Woocommerce using Sage, but you' Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. ### Make the template page override Let's say you want to override a part of a theme in the single product view, like adding some classes to the DIVs that surround the product image. 1. Create a Sage template for the entire page to be modified, using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```/your-theme-root-folder/single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly (It should report: ```Main: single-product.php Base: base.php (by default).```) ### Make the template part 2. Select a function within the that new file which you'd like to be customised, eg change the HTML code within the template part that the hook presents. For instance, here we want to modify the way images are presented, so we need to examine the ```woocommerce_show_product_images``` function within the ```woocommerce_before_single_product_summary``` hook. ```php -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ So, you know how to override a template file in Woocommerce using Sage, but you're having trouble changing something within the deeper level of that template file. For example, you want to change the output HTML structure of a given part of the product page loop, or incorporate a Bootstrap class into a button element without using Jquery to inject it. Here's how you can override deeper level parts of the theme. * Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin. * Also check out how to set up [Sage Templates & Woocommerce](https://roots.io/using-woocommerce-with-sage/) Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ Located at includes/wc-template-functions.php wc_get_template( 'single-product/product-image.php' ); ``` WooCommerce is expecting your overrides to be in: **/your-theme-root-folder/woocommerce/templates/single-product/product-image.php** Sage needs them to be located like so: **/your-theme-root-folder/woocommerce/single-product/product-image.php** -
drawcard revised this gist
Jul 23, 2015 . No changes.There are no files selected for viewing
-
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,8 +54,4 @@ wc_get_template( 'single-product/product-image.php' ); WooCommerce is expecting your overrides to be in: ```/your-theme-root-folder/woocommerce/templates/single-product/product-image.php``` Sage needs them to be located like so: ```/your-theme-root-folder/woocommerce/single-product/product-image.php``` -
drawcard revised this gist
Jul 23, 2015 . 2 changed files with 61 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ So, you know how to override a template file in Woocommerce using Sage, but you're having trouble changing something within the deeper level of that template file. For example, you want to change the output HTML structure of a given part of the product page loop, or incorporate a Bootstrap class into a button element without using Jquery to inject it. Here's how you can override deeper level parts of the theme. 1. Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin. 2. Also check out how to set up [Sage Templates & Woocommerce](https://roots.io/using-woocommerce-with-sage/) Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. Let's say you want to override a part of a theme in the single product view, like adding some classes to the DIVs that surround the product image. 1. Create a Sage template for the entire page to be modified, using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```/your-theme-root-folder/single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly (It should report: ```Main: single-product.php Base: base.php (by default).```) 2. Select a function within the that new file which you'd like to be customised, eg change the HTML code within the template part that the hook presents. For instance, here we want to modify the way images are presented, so we need to examine the ```woocommerce_show_product_images``` function within the ```woocommerce_before_single_product_summary``` hook. ```php <?php /** * woocommerce_before_single_product_summary hook * * @hooked woocommerce_show_product_sale_flash - 10 * @hooked woocommerce_show_product_images - 20 // <---- the function we want */ do_action( 'woocommerce_before_single_product_summary' ); // <---- the hook name ?> ``` 3. Look up the function in [WooCommerce Functions Reference](http://docs.woothemes.com/wc-apidocs/package-WooCommerce.Functions.html) and check out where the function is derived from, eg: ``` Function woocommerce_show_product_images Output the product image before the single product summary. Package: WooCommerce\Functions\Product Author: WooThemes Located at includes/wc-template-functions.php ``` 4. Click on that file reference, eg ```includes/wc-template-functions.php``` to find out what template part the function uses: ```php /** * Output the product image before the single product summary. * * @access public * @subpackage Product * @return void */ function woocommerce_show_product_images() { wc_get_template( 'single-product/product-image.php' ); //<---- the template part } ``` 5. Now we know what template part to override, we simple create that part of the template in Sage, copy and paste the code from the original [WooCommerce template part](https://github.com/woothemes/woocommerce/tree/master/templates) into our new file, and make whatever changes we want to. Use this example as a reference: ```php wc_get_template( 'single-product/product-image.php' ); ``` WooCommerce is expecting your overrides to be in: ```/your-theme-root-folder/woocommerce/templates/single-product/product-image.php``` Sage needs them to be located like so: ```/your-theme-root-folder/woocommerce/single-product/product-image.php``` -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Let's say you want to override a part of a theme in the single product view. 1. Create the Sage template part using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly. 2. Select a hook that you want to be customised, eg change the HTML code within the template part that the hook presents. ```php <?php /** * woocommerce_before_single_product_summary hook @@ -19,7 +19,7 @@ Let's say you want to override a part of a theme in the single product view. */ do_action( 'woocommerce_before_single_product_summary' ); ?> ``` 3. Look up the hook in [WooCommerce Hook Reference](http://docs.woothemes.com/wc-apidocs/hook-docs.html) and check out the php file the hook is derived from, eg -
drawcard revised this gist
Jul 23, 2015 . 1 changed file with 25 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,25 @@ So, you know how to override a template file in Woocommerce using Sage, but you're having trouble changing something within the deeper level of that template file. For example, you want to change the output HTML structure of a given part of the product page loop, or incorporate a Bootstrap class into a button element without using Jquery to inject it. Here's how you can override deeper level parts of the theme. 1. Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin. 2. Also check out how to set up [Sage Templates & Woocommerce](https://roots.io/using-woocommerce-with-sage/) Now you're familiar with how to do Sage + Woocommerce templates, it's time to make it happen. Let's say you want to override a part of a theme in the single product view. 1. Create the Sage template part using these [instructions](https://roots.io/using-woocommerce-with-sage/). In this example we've made ```single-product.php``` and copied the contents of ```/plugins/woocommerce/templates/content-single-product.php``` into it. Then we've used the [Roots Wrapper Toolbar](https://github.com/roots/roots-wrapper-toolbar) to verify that the single-product template is being used by Wordpress correctly. 2. Select a hook that you want to be customised, eg change the HTML code within the template part that the hook presents. `php <?php /** * woocommerce_before_single_product_summary hook * * @hooked woocommerce_show_product_sale_flash - 10 * @hooked woocommerce_show_product_images - 20 */ do_action( 'woocommerce_before_single_product_summary' ); ?> ` 3. Look up the hook in [WooCommerce Hook Reference](http://docs.woothemes.com/wc-apidocs/hook-docs.html) and check out the php file the hook is derived from, eg -
drawcard created this gist
Jul 23, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ 1) Check out the info on how [template overriding works in Woocommerce](http://docs.woothemes.com/document/template-structure/) before you begin.