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
|
terms: [], // List of category and tag objects
|
||||||
search: '', // Search keyword term
|
search: '', // Search keyword term
|
||||||
inclusionType: 'include', // 'include'|'exclude'
|
inclusionType: 'include', // 'include'|'exclude'
|
||||||
displayType: 'titleOnly', // 'short'|'full'|'titleOnly'
|
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
||||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||||
titleIsLink: false, // false|true
|
titleIsLink: false, // false|true
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace MailPoet\Newsletter\Editor;
|
namespace MailPoet\Newsletter\Editor;
|
||||||
|
use MailPoet\WooCommerce\Helper as WooCommerceHelper;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
@@ -10,23 +11,35 @@ class PostContentManager {
|
|||||||
|
|
||||||
public $max_excerpt_length = 60;
|
public $max_excerpt_length = 60;
|
||||||
|
|
||||||
|
/** @var WooCommerceHelper */
|
||||||
|
private $woocommerce_helper;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$wp = new WPFunctions;
|
$wp = new WPFunctions;
|
||||||
$this->max_excerpt_length = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length);
|
$this->max_excerpt_length = $wp->applyFilters('mailpoet_newsletter_post_excerpt_length', $this->max_excerpt_length);
|
||||||
|
$this->woocommerce_helper = new WooCommerceHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContent($post, $displayType) {
|
function getContent($post, $displayType) {
|
||||||
|
$product = null;
|
||||||
|
if ($this->woocommerce_helper->isWooCommerceActive() && $post->post_type === 'product') {
|
||||||
|
$product = wc_get_product($post->ID);
|
||||||
|
}
|
||||||
if ($displayType === 'titleOnly') {
|
if ($displayType === 'titleOnly') {
|
||||||
return '';
|
return '';
|
||||||
} elseif ($displayType === 'excerpt') {
|
} elseif ($displayType === 'excerpt') {
|
||||||
// get excerpt
|
if ($product) {
|
||||||
|
return $product->get_short_description();
|
||||||
|
}
|
||||||
if (!empty($post->post_excerpt)) {
|
if (!empty($post->post_excerpt)) {
|
||||||
return self::stripShortCodes($post->post_excerpt);
|
return self::stripShortCodes($post->post_excerpt);
|
||||||
} else {
|
} else {
|
||||||
return $this->generateExcerpt(self::stripShortCodes($post->post_content));
|
return $this->generateExcerpt(self::stripShortCodes($post->post_content));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($product) {
|
||||||
|
return $product->get_description();
|
||||||
|
}
|
||||||
return self::stripShortCodes($post->post_content);
|
return self::stripShortCodes($post->post_content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,3 +24,6 @@ function wc_price(float $price, array $args = []): string {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wc_get_product($the_product = false, $deprecated = array()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@@ -1337,7 +1337,7 @@
|
|||||||
contentType: 'product',
|
contentType: 'product',
|
||||||
postStatus: 'publish', // 'draft'|'pending'|'publish'
|
postStatus: 'publish', // 'draft'|'pending'|'publish'
|
||||||
inclusionType: 'include', // 'include'|'exclude'
|
inclusionType: 'include', // 'include'|'exclude'
|
||||||
displayType: 'titleOnly', // 'short'|'full'|'titleOnly'
|
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
|
||||||
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
titleFormat: 'h1', // 'h1'|'h2'|'h3'
|
||||||
titleAlignment: 'left', // 'left'|'center'|'right'
|
titleAlignment: 'left', // 'left'|'center'|'right'
|
||||||
titleIsLink: false, // false|true
|
titleIsLink: false, // false|true
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mailpoet_form_field_radio_option">
|
<div class="mailpoet_form_field_radio_option">
|
||||||
<label>
|
<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') %>
|
<%= __('Title and a short description') %>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user