Last active
June 24, 2019 09:52
-
-
Save helgatheviking/ffbf9d1c82351fb9220ff91ce61f7518 to your computer and use it in GitHub Desktop.
Show the KIA Subtitle on WooCommerce products.
This file contains 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 characters
<?php | |
/* | |
* Plugin Name: KIA Subtitle + WooCommerce Bridge | |
* Plugin URI: https://gist.github.com/helgatheviking/ffbf9d1c82351fb9220ff91ce61f7518 | |
* Donate link: https://www.youcaring.com/wnt-residency | |
* Description: Show the KIA Subtitle on WooCommerce products. | |
* Version: 1.0.0 | |
* Author: Kathy Darling | |
* Author URI: http://kathyisawesome.com | |
* Requires at least: 3.8 | |
* Tested up to: 4.7.3 | |
* WC requires at least: 3.0.0 | |
* | |
* Copyright: © 2017 Kathy Darling. | |
* License: GNU General Public License v3.0 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
* | |
*/ | |
// Single product | |
function kia_add_subtitle_to_single_product(){ | |
if( function_exists( 'the_subtitle' ) ) the_subtitle( '<h2 class="subtitle">', '</h2>' ); | |
} | |
add_action( 'woocommerce_single_product_summary', 'kia_add_subtitle_to_single_product', 7 ); | |
// loop product | |
function kia_add_subtitle_to_loop_product(){ | |
if( function_exists( 'the_subtitle' ) ) the_subtitle( '<h4 class="subtitle">', '</h4>' ); | |
} | |
add_action( 'woocommerce_shop_loop_item_title', 'kia_add_subtitle_to_loop_product', 20 ); | |
// shop loop page | |
function kia_add_subtitle_to_shop() { | |
if( function_exists( 'the_subtitle' ) && function_exists( 'is_shop' ) && is_shop() ) { | |
the_subtitle( '<h2 class="subtitle">', '</h2>' ); | |
} | |
} | |
add_action( 'woocommerce_archive_description', 'kia_add_subtitle_to_shop' ); | |
// cart product | |
function kia_add_subtitle_to_cart_product( $title, $cart_item ){ | |
if( function_exists( 'get_the_subtitle' ) && ( $subtitle = get_the_subtitle( $cart_item['product_id'] ) ) ) { | |
$title .= '<br/><span class="subtitle">' . $subtitle . '</span>'; | |
} | |
return $title; | |
} | |
add_filter( 'woocommerce_cart_item_name', 'kia_add_subtitle_to_cart_product', 10, 2 ); | |
// order product | |
function kia_add_subtitle_to_order_product( $title, $order_item, $is_visible = true ){ | |
if( $is_visible && function_exists( 'get_the_subtitle' ) && ( $subtitle = get_the_subtitle( $order_item['product_id'] ) ) ) { | |
$title .= '<br/><span class="subtitle">' . $subtitle . '</span>'; | |
} | |
return $title; | |
} | |
add_filter( 'woocommerce_order_item_name', 'kia_add_subtitle_to_order_product', 10, 3 ); | |
// email product | |
function kia_add_subtitle_to_email_product( $items, $order ){ | |
if( function_exists( 'get_the_subtitle' ) ) { | |
foreach( $items as $item_id => $item ){ | |
if( isset ( $item['product_id'] ) && ( $subtitle = get_the_subtitle( $item['product_id'] ) ) != '' ){ | |
$items[ $item_id ]['name'] = $item['name'] . ': ' . $subtitle; | |
} | |
} | |
} | |
return $items; | |
} | |
add_filter( 'woocommerce_order_get_items', 'kia_add_subtitle_to_email_product', 10, 3 ); | |
Same for me @zackb123. Image attached.
Mix 'n Match = Name
3 for £20 with delivery included = Subtitle
Any help would be appreciated.
My 'hack' would be to just loop once here: "foreach( $items as $item_id => $item ){" not knowing why it pulls the information an additional 5 times I cannot really help further than that. Likely it stems back to the original plugin?
This gist is out of date. Please switch to: https://github.com/helgatheviking/kia-subtitle-woocommerce-bridge
Thanks Kathy! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am having issues with the email portion of this. Where the product name shows in the email to customers and to admin, it is repeating the subtitle multiple times over again after the product title name (i.e. Product name: Subtitle: Subtitle: Subtitle: Subtitle: Subtitle: Subtitle etc.) Any ideas?