Add output methods for search promotion banners

This commit is contained in:
Gerhard 2021-10-12 16:23:28 +02:00
parent 58c26ff11f
commit 0e592e3349
No known key found for this signature in database
GPG Key ID: 147F2060AE23A9A8
2 changed files with 55 additions and 5 deletions

View File

@ -523,6 +523,37 @@ class WC_Admin_Addons {
<?php
}
/**
* Output the HTML for the promotion block
*
* @param array $promotion Array of promotion block data.
* @return void
*/
public static function output_search_promotion_block( array $promotion ) {
?>
<div class="addons-wcs-banner-block">
<div class="addons-wcs-banner-block-image">
<img
class="addons-img"
src="<?php echo esc_url( $promotion['image'] ); ?>"
alt="<?php echo esc_attr( $promotion['image_alt'] ); ?>"
/>
</div>
<div class="addons-wcs-banner-block-content">
<h1><?php echo esc_html( $promotion['title'] ); ?></h1>
<p><?php echo esc_html( $promotion['description'] ); ?></p>
<?php
if ( ! empty( $promotion['actions'] ) ) {
foreach ( $promotion['actions'] as $action ) {
self::output_promotion_action( $action );
}
}
?>
</div>
</div>
<?php
}
/**
* Handles the output of a full-width block.
*
@ -564,7 +595,6 @@ class WC_Admin_Addons {
</div>
<div class="addons-promotion-block-buttons">
<?php
if ( $section['button_1'] ) {
self::output_button(
$section['button_1_href'],
@ -582,7 +612,6 @@ class WC_Admin_Addons {
$section['plugin']
);
}
?>
</div>
</div>
@ -681,6 +710,26 @@ class WC_Admin_Addons {
<?php
}
/**
* Output HTML for a promotion action.
*
* @param array $action Array of action properties.
* @return void
*/
public static function output_promotion_action( array $action ) {
if ( empty( $action ) ) {
return;
}
$style = ( ! empty( $action['primary'] ) && $action['primary'] ) ? 'addons-button-solid' : 'addons-button-outline-purple';
?>
<a
class="addons-button <?php echo esc_attr( $style ); ?>"
href="<?php echo esc_url( $action['url'] ); ?>">
<?php echo esc_html( $action['label'] ); ?>
</a>
<?php
}
/**
* Handles output of the addons page in admin.
@ -853,7 +902,7 @@ class WC_Admin_Addons {
return '';
}
return wp_nonce_url(
wc_admin_url( $action->url ),
admin_url( $action->url ),
$action->nonce
);
}

View File

@ -81,9 +81,10 @@ $current_section_name = __( 'Browse Categories', 'woocommerce' );
<?php endif; ?>
<?php if ( '_featured' !== $current_section && $addons ) : ?>
<?php
print_r( $promotions, true );
if ( ! empty( $promotions ) && WC()->is_wc_admin_active() ) {
foreach ( $promotions as $promotion ) {
WC_Admin_Addons::output_search_promotion_block( $promotion );
}
}
?>
<ul class="products">