PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
convertkit / includes / integrations / woocommerce / class-convertkit-woocommerce-product-form.php

class-convertkit-woocommerce-product-form.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at includes/integrations/woocommerce/class-convertkit-woocommerce-product-form.php

90 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit WooCommerce Product Form class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Outputs ConvertKit Forms on WooCommerce Products.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class ConvertKit_WooCommerce_Product_Form {
16
17 /**
18 * Constructor.
19 *
20 * @since 1.9.6
21 */
22 public function __construct() {
23
24 add_action( 'convertkit_output_output_form', array( $this, 'output_form' ) );
25
26 }
27
28 /**
29 * Output the ConvertKit Form after the Product's Summary, as `the_content` isn't a reliable
30 * hook to use for output when viewing a WooCommerce Product.
31 *
32 * @since 1.9.6
33 */
34 public function output_form() {
35
36 // Bail if WooCommerce isn't active.
37 if ( ! $this->is_active() ) {
38 return;
39 }
40
41 // Bail if not a singular Product.
42 if ( ! is_singular( 'product' ) ) {
43 return;
44 }
45
46 // Remove the_content filter, as this isn't always reliable.
47 remove_filter( 'the_content', array( WP_ConvertKit()->get_class( 'output' ), 'append_form_to_content' ) );
48
49 // Output the Form after the Product's Summary.
50 add_action( 'woocommerce_after_single_product_summary', array( $this, 'append_form_to_product_summary' ) );
51
52 }
53
54 /**
55 * Append the ConvertKit Form to the Product's Summary.
56 *
57 * @since 1.9.6
58 */
59 public function append_form_to_product_summary() {
60
61 // Output is already escaped in append_form_to_content().
62 echo WP_ConvertKit()->get_class( 'output' )->append_form_to_content( '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
63
64 }
65
66 /**
67 * Determines if the WooCommerce Plugin is active.
68 *
69 * @since 1.9.6
70 *
71 * @return bool Plugin Active.
72 */
73 public function is_active() {
74
75 return ( defined( 'WC_PLUGIN_FILE' ) ? true : false );
76
77 }
78
79 }
80
81 // Bootstrap.
82 add_action(
83 'convertkit_initialize_global',
84 function () {
85
86 new ConvertKit_WooCommerce_Product_Form();
87
88 }
89 );
90