Use WC functions to get short and full description in products widget
[MAILPOET-1843]
This commit is contained in:
committed by
Rostislav Wolný
parent
3f9da22500
commit
b40e4bb28a
@@ -44,7 +44,7 @@ Module.ProductsBlockModel = base.BlockModel.extend({
|
||||
terms: [], // List of category and tag objects
|
||||
search: '', // Search keyword term
|
||||
inclusionType: 'include', // 'include'|'exclude'
|
||||
displayType: 'titleOnly', // 'short'|'full'|'titleOnly'
|
||||
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||
titleIsLink: false, // false|true
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Newsletter\Editor;
|
||||
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
@@ -10,23 +11,35 @@ class PostContentManager {
|
||||
|
||||
public $max_excerpt_length = 60;
|
||||
|
||||
/** @var WooCommerceHelper */
|
||||
private $woocommerce_helper;
|
||||
|
||||
function __construct() {
|
||||
$wp = new WPFunctions;
|
||||
$this->max_excerpt_length = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length);
|
||||
$this->woocommerce_helper = new WooCommerceHelper();
|
||||
}
|
||||
|
||||
function getContent($post, $displayType) {
|
||||
$product = null;
|
||||
if ($this->woocommerce_helper->isWooCommerceActive() && $post->post_type === 'product') {
|
||||
$product = wc_get_product($post->ID);
|
||||
}
|
||||
if ($displayType === 'titleOnly') {
|
||||
return '';
|
||||
} elseif ($displayType === 'excerpt') {
|
||||
// get excerpt
|
||||
if ($product) {
|
||||
return $product->get_short_description();
|
||||
}
|
||||
if (!empty($post->post_excerpt)) {
|
||||
return self::stripShortCodes($post->post_excerpt);
|
||||
} else {
|
||||
return $this->generateExcerpt(self::stripShortCodes($post->post_content));
|
||||
}
|
||||
} else {
|
||||
if ($product) {
|
||||
return $product->get_description();
|
||||
}
|
||||
return self::stripShortCodes($post->post_content);
|
||||
}
|
||||
}
|
||||
|
@@ -24,3 +24,6 @@ function wc_price(float $price, array $args = []): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
function wc_get_product($the_product = false, $deprecated = array()) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -1337,7 +1337,7 @@
|
||||
contentType: 'product',
|
||||
postStatus: 'publish', // 'draft'|'pending'|'publish'
|
||||
inclusionType: 'include', // 'include'|'exclude'
|
||||
displayType: 'titleOnly', // 'short'|'full'|'titleOnly'
|
||||
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||
titleIsLink: false, // false|true
|
||||
|
@@ -7,7 +7,7 @@
|
||||
</div>
|
||||
<div class="mailpoet_form_field_radio_option">
|
||||
<label>
|
||||
<input type="radio" name="mailpoet_products_display_type" class="mailpoet_products_display_type" value="short" {{#ifCond model.displayType '==' 'short'}}CHECKED{{/ifCond}}/>
|
||||
<input type="radio" name="mailpoet_products_display_type" class="mailpoet_products_display_type" value="excerpt" {{#ifCond model.displayType '==' 'excerpt'}}CHECKED{{/ifCond}}/>
|
||||
<%= __('Title and a short description') %>
|
||||
</label>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user