Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite $notice to split display and alt text #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions woocommerce-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ function dp_alt_products() {
$alt_products = get_post_meta( $post->ID, '_alt_products', true );
$alt_products = is_array( $alt_products ) ? $alt_products : array();
$notice = dp_alt_products_notice( $post->ID, empty( $alt_products ) );
?>
<?php echo $notice; ?></h4>
<?php

$dp_display_notice = '<h4 class"discontinued-notice">';
$dp_display_notice .= esc_html( $notice[0] );
$dp_display_notice .= '</h4>';

if ( count( $notice ) > 1 ) {
$dp_display_notice .= '<h4 class"discontinued-alt-notice">';
$dp_display_notice .= esc_html( $notice[1] );
$dp_display_notice .= '</h4>';
}
echo $dp_display_notice;

foreach ( $alt_products as $alt_product ) {
?>
<a href="<?php echo esc_url( get_permalink( $alt_product ) ); ?>" class="button"><?php echo get_the_title( $alt_product ); ?></a>
Expand All @@ -56,7 +65,7 @@ function dp_alt_products() {

/**
* Alternative Products Notice.
* Determin notice output for discontinued products based on settings.
* Determine notice output for discontinued products based on settings.
*
* @since 1.1.0
* @param int $product_id ID of the product to check.
Expand All @@ -70,7 +79,7 @@ function dp_alt_products_notice( $product_id, $no_alt ) {
$alt_option = get_option( 'dc_alt_text' );
$text = dp_alt_products_text( $prod_text_option, $text_option, __( 'This product has been discontinued.', 'woocommerce-discontinued-products' ) );
$alt = dp_alt_products_text( $prod_alt_option, $alt_option, __( 'You may be interested in:', 'woocommerce-discontinued-products' ) );
$notice = $no_alt ? '<h4 class="discontinued-notice">' . esc_html($text) . '</H4>' : '<h4 class="discontinued-notice">' . esc_html($text) . '</H4><h4 class="discontinued-notice-alt">' . esc_html($alt) . '</H4>';
$notice = $no_alt ? array( $text ) : array( $text, $alt );
return $notice;
}
}
Expand All @@ -79,7 +88,7 @@ function dp_alt_products_notice( $product_id, $no_alt ) {

/**
* Alternative Products Text.
* Determin text for discontinued products based on settings.
* Determine text for discontinued products based on settings.
*
* @since 1.1.0
* @param string $product_text product meta text.
Expand Down