2
2
/**
3
3
* Custom Emails for WooCommerce - Shortcodes Class
4
4
*
5
- * @version 3.0.1
5
+ * @version 3.0.4
6
6
* @since 1.0.0
7
7
*
8
8
* @author Algoritmika Ltd
@@ -49,7 +49,7 @@ class Alg_WC_Custom_Emails_Shortcodes {
49
49
/**
50
50
* Constructor.
51
51
*
52
- * @version 3.0.1
52
+ * @version 3.0.4
53
53
* @since 1.0.0
54
54
*
55
55
* @todo (dev) not order related (e.g., customer; product)
@@ -95,6 +95,7 @@ function __construct() {
95
95
'order_total_tax ' ,
96
96
'order_user_data ' ,
97
97
'order_user_id ' ,
98
+ 'order_user_meta ' ,
98
99
'order_view_url ' ,
99
100
100
101
'generate_coupon_code ' ,
@@ -366,6 +367,23 @@ function order_customer_note( $atts, $content = '' ) {
366
367
return $ this ->return_shortcode ( $ this ->order ->get_customer_note (), $ atts );
367
368
}
368
369
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
+
369
387
/**
370
388
* order_user_id.
371
389
*
@@ -674,10 +692,63 @@ function add_order_details_product_image( $args ) {
674
692
return $ args ;
675
693
}
676
694
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
+
677
748
/**
678
749
* order_details.
679
750
*
680
- * @version 3.0.1
751
+ * @version 3.0.4
681
752
* @since 1.0.0
682
753
*/
683
754
function order_details ( $ atts , $ content = '' ) {
@@ -687,10 +758,12 @@ function order_details( $atts, $content = '' ) {
687
758
}
688
759
689
760
// 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 ) );
694
767
695
768
// WC Emails
696
769
$ wc_emails = WC_Emails::instance ();
@@ -708,6 +781,16 @@ function order_details( $atts, $content = '' ) {
708
781
add_filter ( 'woocommerce_email_order_items_args ' , array ( $ this , 'add_order_details_product_image ' ), PHP_INT_MAX );
709
782
}
710
783
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
+
711
794
// Order details
712
795
$ wc_emails ->order_details ( $ this ->order , $ sent_to_admin , $ plain_text , $ this ->email );
713
796
@@ -721,6 +804,16 @@ function order_details( $atts, $content = '' ) {
721
804
remove_filter ( 'woocommerce_email_order_items_args ' , array ( $ this , 'add_order_details_product_image ' ), PHP_INT_MAX );
722
805
}
723
806
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
+
724
817
// The end
725
818
return $ this ->return_shortcode ( ob_get_clean (), $ atts );
726
819
0 commit comments