PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.0
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
sellkit / includes / dynamic-keywords / contact-segmentation / categories-in-cart.php

categories-in-cart.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 2.3.0, at includes/dynamic-keywords/contact-segmentation/categories-in-cart.php

74 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Dynamic_Keywords\Contact_Segmentation;
4
5 /**
6 * Class Categeory in cart.
7 *
8 * @package Sellkit\Dynamic_Keywords\Contact_Segmentation
9 * @since 1.1.0
10 */
11 class Categories_In_Cart extends Contact_Segmentation_Base {
12
13 /**
14 * Constructor.
15 *
16 * @since 1.1.0
17 * phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
18 */
19 public function __construct() {
20 parent::__construct();
21 }
22
23 /**
24 * Get class id.
25 *
26 * @return string
27 */
28 public function get_id() {
29 return '_categories_in_cart';
30 }
31
32 /**
33 * Get class title.
34 *
35 * @return string
36 */
37 public function get_title() {
38 return esc_html__( 'Categories in cart', 'sellkit' );
39 }
40
41 /**
42 * Render content.
43 *
44 * @param array $atts array of shortcode arguments.
45 * @return string
46 */
47 public function render_content( $atts ) {
48 if ( empty( self::$cart_items ) ) {
49 return $this->shortcode_content( $atts );
50 }
51
52 $categories = [];
53
54 foreach ( self::$cart_items as $product ) {
55 $terms = wp_get_post_terms( $product['product_id'], 'product_cat', [ 'fields' => 'names' ] );
56 $count = count( $terms );
57
58 if ( $count < 2 ) {
59 $categories[] = isset( $terms[0] ) ? $terms[0] : '';
60 }
61
62 if ( $count > 1 ) {
63 foreach ( $terms as $term ) {
64 $categories[] = $term;
65 }
66 }
67 }
68
69 $categories = $this->get_result( array_unique( $categories ) );
70
71 return implode( ', ', $categories );
72 }
73 }
74