Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ SKU, GTIN (WooCommerce 9.2+), currency, product type, prices, sale end date,
stock, and rating with review count (when ratings are enabled and the product has
reviews); the post author is left out. It also includes product categories, tags,
and registered brands; a price/availability summary; the formatted short
description; visible attributes; and available
variations. Password protection and publication checks still apply.
description under `Summary`; the long description under `Description`; visible
attributes; and available variations. Password protection and publication checks
still apply.

The body uses WooCommerce's displayed prices, including tax settings, currency,
price ranges, active sales, and pricing filters. Numeric frontmatter prices are
catalog values before display-tax adjustments, so they do not depend on who
price ranges, active sales, and pricing filters. The product's price line adds
`(incl. tax)` when shop prices include tax and the product is taxable, except for
VAT-exempt customers. Numeric frontmatter prices are catalog values before
display-tax adjustments, so they do not depend on who
requests the page; `prices_include_tax` says whether those values include tax.
Variable products use `price` and `price_max` for the minimum and maximum catalog
prices. A future sale is not reported as an active sale. SKUs in the body are
Expand Down
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
parameters:
ignoreErrors:
-
message: '#^Call to method is_taxable\(\) on an unknown class WC_Product\.$#'
identifier: class.notFound
count: 1
path: src/Integration/WooCommerce.php

-
message: '#^Function WC not found\.$#'
identifier: function.notFound
count: 2
path: src/Integration/WooCommerce.php

-
message: '#^Call to function is_array\(\) with array will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Yes, as an opt-in. With `add_filter( 'markdown_alternate_skip_noindexed', '__ret
== Changelog ==

= Unreleased =
* Label tax-inclusive displayed product prices and give long product descriptions their own heading.
* Kept author and date archives in HTML instead of redirecting Markdown requests to missing pages
* Fixed cover block images running into the first inner heading
* Omitted aria-hidden and data-URI images from Markdown
Expand Down
8 changes: 7 additions & 1 deletion src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private function format_date( $date ): string {
}

/**
* Add the summary, short description, attributes and variations.
* Add product details and label the long description.
*
* @param array $sections Existing sections.
* @param WP_Post $post The post being rendered.
Expand All @@ -293,6 +293,9 @@ public function add_sections( $sections, $post ): array {
$rows = array();
$price = $this->format_price( $product );
if ( '' !== $price ) {
if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) && $product->is_taxable() && ( ! WC()->customer || ! WC()->customer->get_is_vat_exempt() ) ) {
$price .= ' ' . __( '(incl. tax)', 'markdown-alternate' );
}
$rows[] = '**' . __( 'Price:', 'markdown-alternate' ) . '** ' . $price;
}
if ( '' !== $product->get_sku() ) {
Expand All @@ -313,6 +316,9 @@ public function add_sections( $sections, $post ): array {
'markdown' => '## ' . __( 'Summary', 'markdown-alternate' ) . "\n\n" . $description,
);
}
if ( isset( $sections['content']['markdown'] ) && is_string( $sections['content']['markdown'] ) && '' !== trim( $sections['content']['markdown'] ) ) {
$sections['content']['markdown'] = '## ' . __( 'Description', 'markdown-alternate' ) . "\n\n" . $sections['content']['markdown'];
}
$attributes = $this->build_attributes( $product );
if ( '' !== $attributes ) {
$sections['woo_attributes'] = array(
Expand Down
44 changes: 42 additions & 2 deletions tests/woocommerce-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function md_alt_woo_render( $id ) {
update_option( 'woocommerce_currency', 'EUR' );
update_option( 'woocommerce_calc_taxes', 'no' );
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_tax_display_shop', 'incl' );
md_alt_woo_assert( PostTypeSupport::is_supported( 'product' ) && ! PostTypeSupport::is_supported( 'product_variation' ), 'Products enabled; standalone variations excluded' );

$md_alt_product = new WC_Product_Simple();
Expand Down Expand Up @@ -109,6 +110,34 @@ function md_alt_woo_render( $id ) {
md_alt_woo_assert( false !== strpos( $md_alt_output, '[link](https://example.com)' ) && false !== strpos( $md_alt_output, '- One' ), 'Short description keeps links and lists' );
md_alt_woo_assert( false === strpos( $md_alt_output, '## Attributes' ) && false === strpos( $md_alt_output, '## Variations' ), 'No empty product sections' );
md_alt_woo_assert( false === get_transient( 'md_alt_cache_' . $md_alt_id ), 'Product output is not stored in the shared cache' );
md_alt_woo_assert( false === strpos( $md_alt_output, '(incl. tax)' ), 'Disabled taxes do not add a tax-inclusive label' );
md_alt_woo_assert( false !== strpos( $md_alt_output, "## Summary\n\nShort" ) && false !== strpos( $md_alt_output, "## Description\n\nLong **description**." ), 'Short and long descriptions have separate headings and preserve formatting' );
$md_alt_short_description = $md_alt_product->get_short_description();
$md_alt_product->set_short_description( '' );
$md_alt_product->save();
$md_alt_output = md_alt_woo_render( $md_alt_id );
md_alt_woo_assert( false === strpos( $md_alt_output, '## Summary' ) && false !== strpos( $md_alt_output, '## Description' ), 'Long description has a heading without a short description' );
$md_alt_product->set_description( '' );
$md_alt_product->save();
md_alt_woo_assert( false === strpos( md_alt_woo_render( $md_alt_id ), '## Description' ), 'Empty long description has no heading' );
$md_alt_product->set_description( '<p>Long <strong>description</strong>.</p>' );
$md_alt_product->set_short_description( $md_alt_short_description );
$md_alt_product->save();
$md_alt_content_filter = static function ( $sections ) {
$sections['content'] = array(
'priority' => 125,
'markdown' => 'Custom description.',
);
return $sections;
};
add_filter( 'markdown_alternate_content_sections', $md_alt_content_filter, 5 );
$md_alt_sections = apply_filters( 'markdown_alternate_content_sections', array(), get_post( $md_alt_id ) );
remove_filter( 'markdown_alternate_content_sections', $md_alt_content_filter, 5 );
md_alt_woo_assert( 125 === $md_alt_sections['content']['priority'] && "## Description\n\nCustom description." === $md_alt_sections['content']['markdown'], 'Description heading preserves custom rendered content and priority' );
$md_alt_sections = apply_filters( 'markdown_alternate_content_sections', array(), get_post( $md_alt_id ) );
md_alt_woo_assert( ! isset( $md_alt_sections['content'] ), 'Removed long description is not restored' );
$md_alt_sections = apply_filters( 'markdown_alternate_content_sections', array( 'content' => array( 'markdown' => " \n\t" ) ), get_post( $md_alt_id ) );
md_alt_woo_assert( " \n\t" === $md_alt_sections['content']['markdown'], 'Whitespace-only long description has no heading' );

$md_alt_product->set_date_on_sale_from( time() + DAY_IN_SECONDS );
$md_alt_product->set_price( '20' );
Expand Down Expand Up @@ -223,15 +252,25 @@ function md_alt_woo_render( $id ) {
WC()->customer->set_billing_country( 'NL' );
WC()->customer->set_shipping_country( 'NL' );
$md_alt_output = md_alt_woo_render( $md_alt_id );
md_alt_woo_assert( false !== strpos( $md_alt_output, '24.20' ), 'Displayed price includes shop tax settings' );
md_alt_woo_assert( false !== strpos( $md_alt_output, '**Price:** €24.20 (incl. tax)' ) && false !== strpos( $md_alt_output, "prices_include_tax: false\n" ), 'Tax-inclusive displayed price is labeled independently of catalog tax settings' );
update_option( 'woocommerce_tax_display_shop', 'excl' );
$md_alt_output = md_alt_woo_render( $md_alt_id );
md_alt_woo_assert( false !== strpos( $md_alt_output, '**Price:** €20.00' ) && false === strpos( $md_alt_output, '(incl. tax)' ), 'Tax-exclusive displayed price has no inclusive label' );
update_option( 'woocommerce_tax_display_shop', 'incl' );
foreach ( array( 'none', 'shipping' ) as $md_alt_tax_status ) {
$md_alt_product->set_tax_status( $md_alt_tax_status );
$md_alt_product->save();
md_alt_woo_assert( false === strpos( md_alt_woo_render( $md_alt_id ), '(incl. tax)' ), 'Non-taxable product price has no inclusive label: ' . $md_alt_tax_status );
}
$md_alt_product->set_tax_status( 'taxable' );
// Tax-inclusive catalog prices exercise exemption consistently on older WooCommerce too.
update_option( 'woocommerce_prices_include_tax', 'yes' );
$md_alt_product->set_regular_price( '24.20' );
$md_alt_product->set_price( '24.20' );
$md_alt_product->save();
WC()->customer->set_is_vat_exempt( true );
$md_alt_output = md_alt_woo_render( $md_alt_id );
md_alt_woo_assert( false !== strpos( $md_alt_output, '**Price:** €20.00' ), 'VAT-exempt customer receives their own displayed price' );
md_alt_woo_assert( false !== strpos( $md_alt_output, '**Price:** €20.00' ) && false === strpos( $md_alt_output, '(incl. tax)' ), 'VAT-exempt customer receives their own displayed price without an inclusive label' );
md_alt_woo_assert( false !== strpos( $md_alt_output, "prices_include_tax: true\n" ) && false !== strpos( $md_alt_output, "price: 24.20\n" ), 'Tax-inclusive catalog prices are flagged in frontmatter' );

$md_alt_post_id = wp_insert_post(
Expand All @@ -244,6 +283,7 @@ function md_alt_woo_render( $id ) {
$md_alt_woo_ids[] = $md_alt_post_id;
$md_alt_output = md_alt_woo_render( $md_alt_post_id );
md_alt_woo_assert( false !== get_transient( 'md_alt_cache_' . $md_alt_post_id ) && false === strpos( $md_alt_output, 'product_type:' ), 'Ordinary post output still cached without product metadata' );
md_alt_woo_assert( false === strpos( $md_alt_output, '## Description' ), 'Ordinary posts do not receive a product description heading' );
if ( getenv( 'MD_ALT_TEST_HTTP' ) ) {
$md_alt_permalink = get_permalink( $md_alt_id );
$md_alt_md_url = untrailingslashit( $md_alt_permalink ) . '.md';
Expand Down
Loading