Skip to content

Commit a912a29

Browse files
committed
v3.0.4
1 parent ff6f21c commit a912a29

5 files changed

+269
-65
lines changed

changelog.txt

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
== Changelog ==
22

3+
= 3.0.4 - 18/08/2024 =
4+
* Dev - Shortcodes - `[order_user_meta]` shortcode added.
5+
* Dev - Shortcodes - `[order_details]` - `add_product_desc` attribute added (defaults to `no`).
6+
* Dev - Shortcodes - `[order_details]` - `add_product_short_desc` attribute added (defaults to `no`).
7+
* Tested up to: 6.6.
8+
9+
= 3.0.3 - 30/07/2024 =
10+
* WC tested up to: 9.1
11+
12+
= 3.0.2 - 28/07/2024 =
13+
* WC tested up to: 9.0.
14+
315
= 3.0.1 - 05/06/2024 =
416
* Dev - Shortcodes - `[order_details]` - `add_product_images` attribute added (defaults to `no`).
517
* Dev - Shortcodes - `[order_item_product_images]` shortcode added.

custom-emails-for-woocommerce.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Additional Custom Emails for WooCommerce
44
Plugin URI: https://wpfactory.com/item/custom-emails-for-woocommerce/
55
Description: Add custom emails to WooCommerce.
6-
Version: 3.0.3
6+
Version: 3.0.4
77
Author: WPFactory
88
Author URI: https://wpfactory.com
99
Text Domain: custom-emails-for-woocommerce
@@ -31,7 +31,7 @@
3131
}
3232
}
3333

34-
defined( 'ALG_WC_CUSTOM_EMAILS_VERSION' ) || define( 'ALG_WC_CUSTOM_EMAILS_VERSION', '3.0.3' );
34+
defined( 'ALG_WC_CUSTOM_EMAILS_VERSION' ) || define( 'ALG_WC_CUSTOM_EMAILS_VERSION', '3.0.4' );
3535

3636
defined( 'ALG_WC_CUSTOM_EMAILS_FILE' ) || define( 'ALG_WC_CUSTOM_EMAILS_FILE', __FILE__ );
3737

includes/shortcodes/class-alg-wc-custom-emails-shortcodes.php

+100-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Custom Emails for WooCommerce - Shortcodes Class
44
*
5-
* @version 3.0.1
5+
* @version 3.0.4
66
* @since 1.0.0
77
*
88
* @author Algoritmika Ltd
@@ -49,7 +49,7 @@ class Alg_WC_Custom_Emails_Shortcodes {
4949
/**
5050
* Constructor.
5151
*
52-
* @version 3.0.1
52+
* @version 3.0.4
5353
* @since 1.0.0
5454
*
5555
* @todo (dev) not order related (e.g., customer; product)
@@ -95,6 +95,7 @@ function __construct() {
9595
'order_total_tax',
9696
'order_user_data',
9797
'order_user_id',
98+
'order_user_meta',
9899
'order_view_url',
99100

100101
'generate_coupon_code',
@@ -366,6 +367,23 @@ function order_customer_note( $atts, $content = '' ) {
366367
return $this->return_shortcode( $this->order->get_customer_note(), $atts );
367368
}
368369

370+
/**
371+
* order_user_meta.
372+
*
373+
* @version 3.0.4
374+
* @since 3.0.4
375+
*/
376+
function order_user_meta( $atts, $content = '' ) {
377+
if (
378+
! $this->order ||
379+
! isset( $atts['key'] ) ||
380+
! ( $user_id = $this->order->get_user_id() )
381+
) {
382+
return '';
383+
}
384+
return $this->return_shortcode( get_user_meta( $user_id, $atts['key'], true ), $atts );
385+
}
386+
369387
/**
370388
* order_user_id.
371389
*
@@ -674,10 +692,63 @@ function add_order_details_product_image( $args ) {
674692
return $args;
675693
}
676694

695+
/**
696+
* add_order_details_product_short_desc.
697+
*
698+
* @version 3.0.4
699+
* @since 3.0.4
700+
*/
701+
function add_order_details_product_short_desc( $item_id, $item, $order, $plain_text ) {
702+
$this->add_order_details_product_desc( $item_id, $item, $order, $plain_text, 'short' );
703+
}
704+
705+
/**
706+
* add_order_details_product_long_desc.
707+
*
708+
* @version 3.0.4
709+
* @since 3.0.4
710+
*/
711+
function add_order_details_product_long_desc( $item_id, $item, $order, $plain_text ) {
712+
$this->add_order_details_product_desc( $item_id, $item, $order, $plain_text, 'long' );
713+
}
714+
715+
/**
716+
* add_order_details_product_desc.
717+
*
718+
* @version 3.0.4
719+
* @since 3.0.4
720+
*/
721+
function add_order_details_product_desc( $item_id, $item, $order, $plain_text, $short_or_long ) {
722+
723+
// Get product
724+
if (
725+
! is_callable( array( $item, 'get_product' ) ) ||
726+
! ( $product = $item->get_product() )
727+
) {
728+
return;
729+
}
730+
731+
// Get product description
732+
$product_desc = ( 'short' === $short_or_long ?
733+
$product->get_short_description() :
734+
$product->get_description()
735+
);
736+
if ( '' === $product_desc ) {
737+
return;
738+
}
739+
740+
// Output product description
741+
echo ( $plain_text ?
742+
"\n" . strip_tags( $product_desc ) :
743+
'<br>' . $product_desc
744+
);
745+
746+
}
747+
677748
/**
678749
* order_details.
679750
*
680-
* @version 3.0.1
751+
* @version 3.0.4
681752
* @since 1.0.0
682753
*/
683754
function order_details( $atts, $content = '' ) {
@@ -687,10 +758,12 @@ function order_details( $atts, $content = '' ) {
687758
}
688759

689760
// Atts
690-
$sent_to_admin = ( isset( $atts['sent_to_admin'] ) && filter_var( $atts['sent_to_admin'], FILTER_VALIDATE_BOOLEAN ) );
691-
$plain_text = ( isset( $atts['plain_text'] ) && filter_var( $atts['plain_text'], FILTER_VALIDATE_BOOLEAN ) );
692-
$do_add_product_links = ( isset( $atts['add_product_links'] ) && filter_var( $atts['add_product_links'], FILTER_VALIDATE_BOOLEAN ) );
693-
$do_add_product_images = ( isset( $atts['add_product_images'] ) && filter_var( $atts['add_product_images'], FILTER_VALIDATE_BOOLEAN ) );
761+
$sent_to_admin = ( isset( $atts['sent_to_admin'] ) && filter_var( $atts['sent_to_admin'], FILTER_VALIDATE_BOOLEAN ) );
762+
$plain_text = ( isset( $atts['plain_text'] ) && filter_var( $atts['plain_text'], FILTER_VALIDATE_BOOLEAN ) );
763+
$do_add_product_links = ( isset( $atts['add_product_links'] ) && filter_var( $atts['add_product_links'], FILTER_VALIDATE_BOOLEAN ) );
764+
$do_add_product_images = ( isset( $atts['add_product_images'] ) && filter_var( $atts['add_product_images'], FILTER_VALIDATE_BOOLEAN ) );
765+
$do_add_product_desc = ( isset( $atts['add_product_desc'] ) && filter_var( $atts['add_product_desc'], FILTER_VALIDATE_BOOLEAN ) );
766+
$do_add_product_short_desc = ( isset( $atts['add_product_short_desc'] ) && filter_var( $atts['add_product_short_desc'], FILTER_VALIDATE_BOOLEAN ) );
694767

695768
// WC Emails
696769
$wc_emails = WC_Emails::instance();
@@ -708,6 +781,16 @@ function order_details( $atts, $content = '' ) {
708781
add_filter( 'woocommerce_email_order_items_args', array( $this, 'add_order_details_product_image' ), PHP_INT_MAX );
709782
}
710783

784+
// Product desc
785+
if ( $do_add_product_desc ) {
786+
add_action( 'woocommerce_order_item_meta_end', array( $this, 'add_order_details_product_long_desc' ), 10, 4 );
787+
}
788+
789+
// Product short desc
790+
if ( $do_add_product_short_desc ) {
791+
add_action( 'woocommerce_order_item_meta_end', array( $this, 'add_order_details_product_short_desc' ), 10, 4 );
792+
}
793+
711794
// Order details
712795
$wc_emails->order_details( $this->order, $sent_to_admin, $plain_text, $this->email );
713796

@@ -721,6 +804,16 @@ function order_details( $atts, $content = '' ) {
721804
remove_filter( 'woocommerce_email_order_items_args', array( $this, 'add_order_details_product_image' ), PHP_INT_MAX );
722805
}
723806

807+
// Product desc
808+
if ( $do_add_product_desc ) {
809+
remove_action( 'woocommerce_order_item_meta_end', array( $this, 'add_order_details_product_long_desc' ), 10 );
810+
}
811+
812+
// Product short desc
813+
if ( $do_add_product_short_desc ) {
814+
remove_action( 'woocommerce_order_item_meta_end', array( $this, 'add_order_details_product_short_desc' ), 10 );
815+
}
816+
724817
// The end
725818
return $this->return_shortcode( ob_get_clean(), $atts );
726819

0 commit comments

Comments
 (0)