Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
<?php
if ( ! class_exists( 'BWFAN_Create_Offer_Recovery_Link' ) ) {
final class BWFAN_Create_Offer_Recovery_Link extends BWFAN_Action {
private static $ins = null;
protected function __construct() {
$this->action_name = __( 'Create Offer Recovery Link', 'wp-marketing-automations-pro' );
$this->action_desc = __( 'This action creates a Stripe Offer recovery link', 'wp-marketing-automations-pro' );
$this->required_fields = array( 'funnel_id', 'offer_id' );
$this->action_priority = 5;
$this->support_v2 = true;
$this->support_v1 = false;
$this->analytics_mode = 'upsell-recovery';
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Make all the data which is required by the current action.
* This data will be used while executing the task of this action.
*
* @param $automation_data
* @param $step_data
*
* @return array|void
*/
public function make_v2_data( $automation_data, $step_data ) {
$data_to_set = [];
$data_to_set['email'] = $automation_data['global']['email'];
$data_to_set['saved_offer_id'] = isset( $step_data['offer'][0]['id'] ) ? $step_data['offer'][0]['id'] : 0;
$contact_id = isset( $automation_data['global']['cid'] ) ? $automation_data['global']['cid'] : 0;
$data_to_set['contact_id'] = empty( $contact_id ) && isset( $automation_data['global']['contact_id'] ) ? $automation_data['global']['contact_id'] : $contact_id;
$data_to_set['order_id'] = isset( $automation_data['global']['order_id'] ) ? $automation_data['global']['order_id'] : 0;
$data_to_set['step_id'] = isset( $automation_data['step_id'] ) ? $automation_data['step_id'] : 0;
$data_to_set['expiry'] = isset( $step_data['expiry'] ) ? $step_data['expiry'] : 0;
return $data_to_set;
}
public function process_v2() {
$data = $this->data;
$hash_code = md5( time() . $data['contact_id'] );
$link_data = [
'cid' => $data['contact_id'],
'hash_code' => $hash_code,
'oid' => $data['saved_offer_id'],
'fid' => WFOCU_Core()->offers->get_parent_funnel( $data['saved_offer_id'] ), // upsell id
'created_at' => current_time( 'mysql' ),
'expiry_days' => $data['expiry'],
'updated_at' => current_time( 'mysql' ),
'sid' => $data['step_id'],
'clicked' => 0,
];
$link_obj = new BWFAN_Generate_Offer_Link( 0, '', $link_data );
$offer_link_id = $link_obj->save();
/** update new coupon value in automation contact row */
$row_data = $this->get_automation_contact_row( $data['automation_contact_id'] );
if ( ! empty( $row_data ) ) {
$offer_links = isset( $row_data['offer_links'] ) && is_array( $row_data['offer_links'] ) ? $row_data['offer_links'] : [];
$offer_links[ $data['step_id'] ] = $offer_link_id;
$row_data['offer_links'] = $offer_links;
BWFAN_Model_Automation_Contact::update( array(
'data' => wp_json_encode( $row_data )
), array(
'ID' => $data['automation_contact_id'],
) );
}
/** using special property to end the current automation process for a contact */
BWFAN_Common::$end_v2_current_contact_automation = true;
return $this->success_message( __( 'Offer recovery link created', 'wp-marketing-automations-pro' ) );
}
/**
* Get automation contact row data only
*
* @param $automation_contact_id
*
* @return mixed|void|null
*/
public function get_automation_contact_row( $automation_contact_id ) {
if ( empty( $automation_contact_id ) ) {
return;
}
$automation_contact_data = BWFAN_Model_Automation_Contact::get_data( $automation_contact_id );
if ( empty( $automation_contact_data ) ) {
return;
}
return json_decode( $automation_contact_data['data'], true );
}
public function get_fields_schema() {
$filter_driven_settings = [];
if ( true === apply_filters( 'bwfan_upsell_merge_order_setting', false ) ) {
$filter_driven_settings = [
[
'id' => 'order-settings',
'label' => __( 'Order Settings', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Create a new Order', 'wp-marketing-automations-pro' ),
'value' => 'new'
],
[
'label' => __( 'Merged with the main order', 'wp-marketing-automations-pro' ),
'value' => 'merge'
],
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => true,
"description" => ""
],
[
'id' => 'merge_hrs',
'type' => 'number',
'value' => "5",
'label' => __( 'Merge order if parent order was purchased following hrs', 'wp-marketing-automations-pro' ),
"description" => "",
'toggler' => [
'fields' => [
[
'id' => 'order-settings',
'value' => 'merge',
]
]
],
]
];
}
$settings = [
[
'id' => 'title',
'type' => 'text',
'label' => __( 'Stripe Offer Title', 'wp-marketing-automations-pro' ),
"description" => "",
"tip" => __( 'Stripe Offer title is for internal usage, visible only to admins.', 'wp-marketing-automations-pro' ),
"required" => true,
],
[
'id' => 'mergetag',
'type' => 'dynamic_merge_tag',
'innerText' => __( 'This offer link can be used in emails or other actions using merge tag :', 'wp-marketing-automations-pro' ),
'merge_data' => [
'sid' => 'stepid',
],
'merge_tag_slug' => 'stripe_offer_recovery_link',
'toggler' => [
'fields' => array(
[
'id' => 'title',
'value' => '',
],
),
'relation' => 'AND',
]
],
[
"id" => 'offer',
"label" => __( 'Select Offer', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'fk_fetch_offers',
'slug' => 'fk_fetch_offers',
'labelText' => 'Offer'
],
"allowFreeTextSearch" => false,
"required" => true,
"multiple" => false,
],
[
'id' => 'expiry',
'type' => 'number',
'label' => __( 'Offer Link Expiry in Days', 'wp-marketing-automations-pro' ),
"hint" => __( 'Default expiry is 10 days', 'wp-marketing-automations-pro' ),
"required" => true,
],
];
return array_merge( $settings, $filter_driven_settings );
}
/**
* Default values for goal values
*
* @return array
*/
public function get_default_values() {
return [
'order-settings' => 'new',
'expiry' => '10',
];
}
public function get_desc_text( $data ) {
$data = json_decode( wp_json_encode( $data ), true );
if ( ! isset( $data['coupon_data'] ) || empty( $data['coupon_data'] ) || ! isset( $data['coupon_data']['general'] ) ) {
return '';
}
$text = isset( $data['coupon_data']['general']['coupon_prefix'] ) ? $data['coupon_data']['general']['coupon_prefix'] : '';
return $text . '{random_6_digits}';
}
}
/**
* Register this action. Registering the action will make it eligible to see it on single automation screen in select actions dropdown.
*/
return 'BWFAN_Create_Offer_Recovery_Link';
}

View File

@@ -0,0 +1,31 @@
<?php
if ( ! class_exists( 'BWFAN_Upsell_Stripe_Integration' ) ) {
final class BWFAN_Upsell_Stripe_Integration extends BWFAN_Integration {
private static $ins = null;
protected $need_connector = false;
private function __construct() {
$this->action_dir = __DIR__;
$this->nice_name = __( 'Stripe', 'wp-marketing-automations-pro' );
$this->group_name = __( 'Stripe', 'wp-marketing-automations-pro' );
$this->group_slug = 'stripe';
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
}
/**
* Register this class as an integration.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_builder_pro_active() && bwfan_is_fk_stripe_active() ) {
BWFAN_Load_Integrations::register( 'BWFAN_Upsell_Stripe_Integration' );
}
}

View File

@@ -0,0 +1,38 @@
<?php
if ( ! class_exists( 'BWFAN_Stripe_Upsell_Source' ) ) {
class BWFAN_Stripe_Upsell_Source extends BWFAN_Source {
private static $instance = null;
public function __construct() {
$this->event_dir = __DIR__;
$this->nice_name = __( 'Stripe', 'wp-marketing-automations-pro' );
$this->group_name = __( 'Stripe', 'wp-marketing-automations-pro' );
$this->group_slug = 'stripe';
$this->priority = 11;
}
/**
* Ensures only one instance of the class is loaded or can be loaded.
*
* @return BWFAN_Stripe_Upsell_Source|null
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function get_group_notice_text() {
return __( "Every missed offer is a missed sale, don't let it stay that way! With FunnelKit Stripe, you can follow up via Email or SMS and recover rejected Order Bumps or Upsells. Go to connectors now to connect Stripe and recover more revenue!", 'wp-marketing-automations-pro' );
}
}
/**
* Register this as a source.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_builder_pro_active() && bwfan_is_fk_stripe_active() ) {
BWFAN_Load_Sources::register( 'BWFAN_Stripe_Upsell_Source' );
}
}

View File

@@ -0,0 +1,466 @@
<?php
if ( ! class_exists( 'BWFAN_Stripe_Offer_Rejected' ) ) {
final class BWFAN_Stripe_Offer_Rejected extends BWFAN_Event {
private static $instance = null;
public $order = null;
public $order_id = 0;
public $funnel_id = null;
public $object_id = null;
public $offer_type = null;
private function __construct() {
$this->event_merge_tag_groups = array( 'bwf_contact', 'wc_order', 'wc_funnel', 'wc_offer' );
$this->optgroup_label = esc_html__( 'Stripe', 'wp-marketing-automations-pro' );
$this->event_name = esc_html__( 'Recover Offers', 'wp-marketing-automations-pro' );
$this->event_desc = esc_html__( 'This event runs after an offer is rejected by the customer and payment gateway is FunnelKit Stripe.', 'wp-marketing-automations-pro' );
$this->event_rule_groups = array(
'wc_order',
'wc_customer',
'bwf_contact_segments',
'bwf_contact',
'bwf_contact_fields',
'bwf_contact_user',
'bwf_contact_wc',
'bwf_contact_geo',
'bwf_engagement',
'bwf_broadcast',
'woofunnels',
'fk_stripe_upsell',
);
$this->support_lang = true;
$this->priority = 45.4;
$this->v2 = true;
$this->support_v1 = false;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function load_hooks() {
add_action( 'bwf_normalize_contact_meta_before_save', [ $this, 'capture_rejected_offer' ], 9999, 3 );
add_action( 'woocommerce_thankyou', [ $this, 'capture_rejected_bump' ], 98, 1 );
}
/**
* @param $contact
* @param $order_id
* @param $order WC_Order
*
* @return void
*/
public function capture_rejected_offer( $contact, $order_id, $order ) {
BWFAN_Core()->public->load_active_v2_automations( $this->get_slug() );
if ( ! is_array( $this->automations_v2_arr ) || count( $this->automations_v2_arr ) === 0 ) {
return;
}
/** Check automation is already run on this order */
$this->automations_v2_arr = $this->maybe_automation_has_already_run( $this->automations_v2_arr, $order );
if ( count( $this->automations_v2_arr ) === 0 ) {
return;
}
/** Get rejected offers */
$offers = $this->get_rejected_offers( $order_id );
if ( empty( $offers ) ) {
return;
}
$this->process( $offers );
}
/**
* Check automation has already run for order
*
* @param $automations_v2_arr
* @param $order
*
* @return array
*/
public function maybe_automation_has_already_run( $automations_v2_arr, $order ) {
if ( ! $order instanceof WC_Order ) {
return [];
}
$already_run_automation = $order->get_meta( 'fka_offer_already_rejected' );
$exclude_aids = is_array( $already_run_automation ) ? array_map( 'intval', array_keys( $already_run_automation ) ) : [];
if ( empty( $exclude_aids ) ) {
return $automations_v2_arr;
}
return array_filter( $automations_v2_arr, function ( $v2_automation ) use ( $exclude_aids ) {
if ( in_array( intval( $v2_automation['id'] ), $exclude_aids, true ) ) {
return false;
}
return $v2_automation;
} );
}
public function get_rejected_offers( $order_id ) {
global $wpdb;
$query = "SELECT session.*, event.object_type,GROUP_CONCAT(DISTINCT event.object_id) as object_id FROM {$wpdb->prefix}wfocu_event AS event LEFT JOIN {$wpdb->prefix}wfocu_session AS session ON event.sess_id = session.id WHERE event.action_type_id=6 AND session.order_id = %d GROUP BY session.order_id, session.email ORDER BY session.cid DESC";
$res = $wpdb->get_results( $wpdb->prepare( $query, $order_id ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $res ) ) {
return [];
}
/** Convert comma separate object id in as array */
$offer = array_map( function ( $offer ) {
$offer['object_id'] = explode( ',', $offer['object_id'] );
return $offer;
}, $res );
return isset( $offer[0] ) ? $offer[0] : [];
}
/**
* Make the required data for the current event and run it.
*
* @param $data
*/
public function process( $data ) {
$order = wc_get_order( $data['order_id'] );
if ( ! $order instanceof WC_Order ) {
return;
}
/** Checking payment gateway */
if ( false === strpos( $order->get_payment_method(), 'fkwcs' ) ) {
return;
}
$this->order_id = $data['order_id'];
$this->order = $order;
$this->funnel_id = isset( $data['fid'] ) ? $data['fid'] : 0;
$this->object_id = isset( $data['object_id'] ) ? $data['object_id'] : 0;
$contact_data_v2 = array(
'order_id' => $this->order_id,
'email' => $order->get_billing_email(),
'user_id' => $order->get_user_id(),
'event' => $this->get_slug(),
'object_id' => $this->object_id,
'fid' => $this->funnel_id,
'type' => isset( $data['object_type'] ) ? $data['object_type'] : 'bump',
'version' => 2
);
BWFAN_Common::maybe_run_v2_automations( $this->get_slug(), $contact_data_v2 );
/** Set flag to run once per order in order meta */
if ( ! empty( BWFAN_Common::$last_automation_cid ) ) {
$saved_aids = ! empty( $order->get_meta( 'fka_offer_already_rejected' ) ) ? $order->get_meta( 'fka_offer_already_rejected' ) : [];
$aids = ! empty( $saved_aids ) ? array_replace( $saved_aids, BWFAN_Common::$last_automation_cid ) : BWFAN_Common::$last_automation_cid;
$order->update_meta_data( 'fka_offer_already_rejected', $aids );
$order->save();
}
}
/**
* @param $order_id
*
* @return void
*/
public function capture_rejected_bump( $order_id ) {
BWFAN_Core()->public->load_active_v2_automations( $this->get_slug() );
if ( ! is_array( $this->automations_v2_arr ) || count( $this->automations_v2_arr ) === 0 ) {
return;
}
$order = wc_get_order( $order_id );
$this->automations_v2_arr = $this->maybe_automation_has_already_run( $this->automations_v2_arr, $order );
if ( count( $this->automations_v2_arr ) === 0 ) {
return;
}
/** Get bumps from order */
$bumps = $order->get_meta( '_wfob_report_data' );
if ( empty( $bumps ) ) {
return;
}
$data = [
'order_id' => $order_id,
];
foreach ( $bumps as $bump ) {
/** Continue if bump is accepted */
if ( 0 !== intval( $bump['converted'] ) ) {
continue;
}
$data['fid'] = $bump['fid'];
$data['object_id'][] = $bump['bid'];
}
$this->process( $data );
}
/**
* Get data
*
* @return array|array[]
*/
public function get_event_data() {
$data_to_send = [ 'global' => [] ];
$this->order = ! $this->order instanceof WC_Order ? wc_get_order( $this->order_id ) : $this->order;
$data_to_send['global']['order_id'] = $this->order_id;
$data_to_send['global']['wc_order'] = $this->order instanceof WC_Order ? $this->order : '';
$data_to_send['global']['email'] = $this->order instanceof WC_Order ? BWFAN_Woocommerce_Compatibility::get_billing_email( $this->order ) : '';
$data_to_send['global']['funnel_id'] = $this->order instanceof WC_Order ? $this->order->get_meta( '_wfocu_funnel_id' ) : $this->funnel_id;
$data_to_send['global']['object_id'] = $this->object_id;
return $data_to_send;
}
/**
* Validate v2 event setting
*
* @param $automation_data
*
* @return bool
*/
public function validate_v2_event_settings( $automation_data ) {
if ( ! isset( $automation_data['event_meta'] ) ) {
return false;
}
if ( 'both' !== $automation_data['event_meta']['type'] && $automation_data['type'] !== $automation_data['event_meta']['type'] ) {
return false;
}
/** Validate automation if contact is already exists with same order */
if ( false === $this->validate_automation( $automation_data ) ) {
return false;
}
/** If type is offer */
if ( ( 'both' === $automation_data['event_meta']['type'] && 'offer' === $automation_data['type'] ) || 'offer' === $automation_data['event_meta']['type'] ) {
return $this->validate_offer_setting( $automation_data );
}
/** If type is bump */
return $this->validate_offer_setting( $automation_data, 'bump' );
}
/**
* @param $automation_data
*
* @return bool
*/
public function validate_automation( $automation_data ) {
$global_data = BWFAN_Common::get_global_data( $this->get_event_data() );
$cid = isset( $global_data['global']['contact_id'] ) ? $global_data['global']['contact_id'] : 0;
$cid = empty( $cid ) && isset( $global_data['global']['cid'] ) ? $global_data['global']['cid'] : $cid;
if ( empty( $cid ) ) {
return false;
}
/** Check if contact is already exists in automation with same order */
if ( BWFAN_Common::is_contact_in_automation( $automation_data['id'], $cid, $automation_data['order_id'], 0, 'stripe_upsell_offer_rejected' ) ) {
return false;
}
return true;
}
/**
* Validate offer and bump settings
*
* @param $automation_data
* @param string $type
*
* @return bool
*/
public function validate_offer_setting( $automation_data, string $type = 'offer' ) {
if ( ! isset( $automation_data['event_meta'][ $type . '-contains' ] ) ) {
return false;
}
if ( 'any' === $automation_data['event_meta'][ $type . '-contains' ] ) {
return true;
}
if ( ! isset( $automation_data['event_meta'][ $type . '_id' ] ) || ! isset( $automation_data['object_id'] ) ) {
return false;
}
$offer_ids = array_map( 'intval', array_column( $automation_data['event_meta'][ $type . '_id' ], 'id' ) );
if ( is_array( $automation_data['object_id'] ) ) {
return count( array_intersect( $automation_data['object_id'], $offer_ids ) ) > 0;
}
return in_array( intval( $automation_data['object_id'] ), $offer_ids, true );
}
/**
* Get setting's field schema
*
* @return array[]
*/
public function get_fields_schema() {
return [
[
'id' => 'type',
'label' => __( 'Type', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Offer Rejected', 'wp-marketing-automations-pro' ),
'value' => 'offer'
],
[
'label' => __( 'Bump Rejected', 'wp-marketing-automations-pro' ),
'value' => 'bump'
],
[
'label' => __( 'Both', 'wp-marketing-automations-pro' ),
'value' => 'both'
],
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => true,
"description" => ""
],
[
'id' => 'offer-contains',
'label' => __( 'Offer Contains', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Any Offer', 'wp-marketing-automations-pro' ),
'value' => 'any'
],
[
'label' => __( 'Specific Offers', 'wp-marketing-automations-pro' ),
'value' => 'selected_offer'
],
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => true,
"description" => "",
'toggler' => [
'fields' => [
[
'id' => 'type',
'value' => [ 'offer', 'both' ],
],
],
'relation' => 'OR'
],
],
[
'id' => 'offer_id',
'label' => __( 'Select Offers', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'fk_fetch_offers',
'slug' => 'fk_fetch_offers',
'labelText' => 'Offer'
],
'class' => '',
'placeholder' => '',
'required' => true,
'toggler' => [
'fields' => [
[
'id' => 'offer-contains',
'value' => 'selected_offer',
],
[
'id' => 'type',
'value' => [ 'offer', 'both' ],
],
],
'relation' => 'AND'
],
],
[
'id' => 'bump-contains',
'label' => __( 'Bump Contains', 'wp-marketing-automations-pro' ),
'type' => 'radio',
'options' => [
[
'label' => __( 'Any Bump', 'wp-marketing-automations-pro' ),
'value' => 'any'
],
[
'label' => __( 'Specific Bumps', 'wp-marketing-automations-pro' ),
'value' => 'selected_bump'
],
],
"class" => 'bwfan-input-wrapper',
"tip" => "",
"required" => true,
"description" => "",
'toggler' => [
'fields' => [
[
'id' => 'type',
'value' => [ 'bump', 'both' ],
],
],
'relation' => 'OR'
],
],
[
'id' => 'bump_id',
'label' => __( 'Select Bumps', 'wp-marketing-automations-pro' ),
"type" => 'custom_search',
'autocompleterOption' => [
'path' => 'fk_fetch_bumps',
'slug' => 'fk_fetch_bumps',
'labelText' => 'Bump'
],
'class' => '',
'placeholder' => '',
'required' => true,
'toggler' => [
'fields' => [
[
'id' => 'bump-contains',
'value' => 'selected_bump',
],
[
'id' => 'type',
'value' => [ 'bump', 'both' ],
],
],
'relation' => 'AND'
],
],
];
}
/**
* Default values for goal values
*
* @return array
*/
public function get_default_values() {
return [
'type' => 'offer',
'offer-contains' => 'any',
'order-settings' => 'new',
'bump-contains' => 'any',
];
}
}
/**
* Register this event to a source.
* This will show the current event in dropdown in single automation screen.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_builder_pro_active() && bwfan_is_fk_stripe_active() ) {
return 'BWFAN_Stripe_Offer_Rejected';
}
}

View File

@@ -0,0 +1,508 @@
<?php
if ( ! class_exists( 'BWFAN_Generate_Offer_Link_Handler' ) ) {
final class BWFAN_Generate_Offer_Link_Handler {
public static $instance = null;
public function __construct() {
add_action( 'wp_loaded', [ $this, 'handle_offer_link' ], 101 );
add_filter( 'wfocu_get_funnel_option', [ $this, 'funnel_settings' ], 10, 2 );
add_filter( 'bwfan_automation_node_analytics', array( $this, 'action_node_analytics' ), 10, 4 );
/** Ensure Thank you page open of Funnel */
add_action( 'wfocu_offer_accepted_and_processed', array( $this, 'maybe_set_current_order' ), 1, 5 );
add_filter( 'wfocu_modify_error_json_response', array( $this, 'provide_pay_link_on_error' ), 10, 4 );
add_filter( 'wffn_wfty_filter_page_ids', array( $this, 'maybe_filter_thankyou' ), 99, 2 );
add_action( 'woocommerce_thankyou', array( $this, 'maybe_log_thankyou_visited' ), 999 );
add_action( 'wfocu_offer_rejected_event', array( $this, 'redirect_to_home' ), 1000000 );
add_filter( 'wfocu_get_offer_id_filter', array( $this, 'return_offer_zero' ), 1000000 );
}
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Handle offer recovery link
*
* @return void
* @throws DateMalformedStringException
*/
public function handle_offer_link() {
/** Display notice if link is expired */
if ( function_exists( 'wc_add_notice' ) && isset( $_GET['bwfan-link-expired'] ) ) {
wc_add_notice( 'Link has been expired!', 'notice' );
return;
}
if ( ! isset( $_GET['bwfan-offer-code'] ) || empty( $_GET['bwfan-offer-code'] ) ) {
return;
}
$offer_hash = filter_input( INPUT_GET, 'bwfan-offer-code' );
$order_id = filter_input( INPUT_GET, 'order_id' );
$link_obj = new BWFAN_Generate_Offer_Link( 0, $offer_hash, [ 'clicked' => 1 ] );
/** Save click */
$link_obj->save();
$expiry_days = $link_obj->get_expiry_days();
$create_time = DateTime::createFromFormat( 'Y-m-d H:i:s', $link_obj->get_create_date() );
$expiry_date = clone $create_time;
$expiry_date = $expiry_date->modify( "+$expiry_days days" );
/** Checking if link is expired */
if ( current_time( 'timestamp' ) > $expiry_date->getTimestamp() ) {
wp_safe_redirect( home_url( '?bwfan-link-expired=1' ) );
exit;
}
$offer_data = $link_obj->get_data();
if ( class_exists( 'WFFN_Core' ) && is_array( $offer_data ) && isset( $offer_data['fid'] ) ) {
/**
* Get wffn funnel id by upsell id for increase funnel view
*/
$funnel_id = get_post_meta( $offer_data['fid'], '_bwf_in_funnel', true );
if ( ! empty( $funnel_id ) && class_exists( 'WFFN_Core' ) ) {
WFFN_Core()->public->increase_funnel_visit_session_view( $funnel_id );
}
}
$offer_recovery_link = $link_obj->generate_upsell_link( $order_id );
$offer_recovery_link = empty( $offer_recovery_link ) ? home_url() : $offer_recovery_link;
BWFAN_PRO_Common::wp_redirect( $offer_recovery_link );
exit;
}
/**
* Get step data
*
* @param $sid
*
* @return array
*/
public static function get_step_data( $sid ) {
$step = BWFAN_Model_Automation_Step::get_step_data_by_id( $sid );
$data = isset( $step['data'] ) && BWFAN_Common::is_json( $step['data'] ) ? json_decode( $step['data'], true ) : [];
return isset( $data['sidebarData'] ) ? $data['sidebarData'] : [];
}
/**
* Modify upsell setting
*
* @param $options
* @param $key
*
* @return mixed|string
*/
public function funnel_settings( $options, $key ) {
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return $options;
}
$is_merge = $this->is_order_merge();
if ( 'order_behavior' === $key && true === $is_merge ) {
return 'batching';
}
if ( 'order_behavior' === $key ) {
return 'create_order';
}
if ( 'is_cancel_order' === $key ) {
return 'no';
}
return $options;
}
/**
* Check settings for order will merge or will create new order
*
* @return bool
*/
public function is_order_merge() {
$sid = WFOCU_Core()->data->get( 'fka_sid' );
$create_time = WFOCU_Core()->data->get( 'fka_upsell_created_at' );
$step_data = self::get_step_data( $sid );
if ( ! isset( $step_data['order-settings'] ) || 'new' === $step_data['order-settings'] ) {
return false;
}
$merge_hrs = isset( $step_data['merge_hrs'] ) ? intval( $step_data['merge_hrs'] ) : 0;
if ( empty( $merge_hrs ) ) {
return false;
}
$create_time = DateTime::createFromFormat( 'Y-m-d H:i:s', $create_time );
$expiry_date = clone $create_time;
$expiry_date = $expiry_date->modify( "+$merge_hrs hours" );
/** If given time is exceed */
if ( current_time( 'timestamp' ) > $expiry_date->getTimestamp() ) {
return false;
}
return true;
}
/**
* Return the node analytics of mode upsell-recovery
*
* @param $data
* @param $automation_id
* @param $step_id
* @param $mode
*
* @return array
*/
public function action_node_analytics( $data, $automation_id, $step_id, $mode ) {
/** If step is upsell recovery */
if ( 'upsell-recovery' !== $mode ) {
return $data;
}
$data = BWFAN_Model_Stripe_Offer::get_analytics( $step_id );
$sent = isset( $data['sent'] ) ? $data['sent'] : 0;
$click_rate = isset( $data['click_rate'] ) ? number_format( $data['click_rate'], 2 ) : 0;
$click_count = isset( $data['click_count'] ) ? $data['click_count'] : 0;
$conversions = isset( $data['conversions'] ) ? absint( $data['conversions'] ) : 0;
$revenue = isset( $data['revenue'] ) ? floatval( $data['revenue'] ) : 0;
$contacts_count = isset( $data['contacts_count'] ) ? absint( $data['contacts_count'] ) : 1;
$rev_per_person = empty( $contacts_count ) || empty( $revenue ) ? 0 : number_format( $revenue / $contacts_count, 2 );
$tiles = [
[
'label' => __( 'Created', 'wp-marketing-automations-pro' ),
'value' => empty( $sent ) ? '-' : $sent,
],
[
'label' => __( 'Click Rate', 'wp-marketing-automations-pro' ),
'value' => empty( $click_rate ) ? '-' : $click_rate . ' (' . $click_count . ')',
],
];
if ( bwfan_is_woocommerce_active() ) {
$currency_symbol = get_woocommerce_currency_symbol();
$revenue = html_entity_decode( $currency_symbol . $revenue );
$rev_per_person = html_entity_decode( $currency_symbol . $rev_per_person );
$revenue_tiles = [
[
'label' => __( 'Revenue', 'wp-marketing-automations-pro' ),
'value' => empty( $conversions ) ? '-' : $revenue . ' (' . $conversions . ')',
],
[
'label' => __( 'Revenue/Contact', 'wp-marketing-automations-pro' ),
'value' => empty( $contacts_count ) ? '-' : $rev_per_person,
]
];
$tiles = array_merge( $tiles, $revenue_tiles );
}
return [
'status' => true,
'data' => [
'analytics' => [],
'tile' => $tiles,
]
];
}
/**
* Set current order as the one
*
* @param $get_offer_id
* @param $get_package
* @param $get_parent_order
* @param $new_order
*
* @return void
*/
public function maybe_set_current_order( $get_offer_id, $get_package, $get_parent_order, $new_order ) {
if ( ! $new_order instanceof WC_Order ) {
return;
}
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return;
}
$upsell_id = get_post_meta( $get_offer_id, '_funnel_id', true );
/** This new order is from FKA Stripe offer */
$new_order->update_meta_data( '_bwfan_stripe_offer', '1' );
if ( ! empty( $upsell_id ) && absint( $upsell_id ) > 0 ) {
$new_order->update_meta_data( '_wfocu_funnel_id', $upsell_id );
}
$new_order->save_meta_data();
WFOCU_Core()->data->set( 'corder', WFOCU_WC_Compatibility::get_order_id( $new_order ), 'orders' );
WFOCU_Core()->data->set( 'corder', $new_order, '_orders' );
WFOCU_Core()->data->save( 'orders' );
/** Removing the action */
remove_action( 'wfocu_offer_accepted_event', array( WFOCU_DB_Track::get_instance(), 'add_to_order_meta' ), 990 );
add_action( 'wfocu_offer_accepted_event', array( $this, 'add_to_order_meta' ), 899 );
/** Save order details in offer table */
$p_key = WFOCU_Core()->data->get( 'fka_p_key' );
if ( intval( $p_key ) > 0 ) {
$data = [
'order_id' => $new_order->get_id(),
'order_total' => BWF_Plugin_Compatibilities::get_fixed_currency_price_reverse( $new_order->get_total(), BWF_WC_Compatibility::get_order_currency( $new_order ) ),
'order_date' => $new_order->get_date_created()->format( 'Y-m-d H:i:s' ),
];
$link_obj = new BWFAN_Generate_Offer_Link( $p_key, '', $data );
$link_obj->save();
}
}
public function add_to_order_meta( $args ) {
$get_current_order_id = isset( $args['new_order'] ) ? $args['new_order'] : '';
if ( empty( $get_current_order_id ) ) {
$get_current_order_id = WFOCU_Core()->data->get( 'corder', false, 'orders' );
}
if ( empty( $get_current_order_id ) ) {
return;
}
$get_order = wc_get_order( $get_current_order_id );
if ( ! $get_order instanceof WC_Order ) {
return;
}
$total_sum = floatval( $args['value'] );
$total_sum_currency = floatval( $args['value_in_currency'] );
if ( 0 < $total_sum ) {
$get_order->update_meta_data( '_wfocu_upsell_amount', $total_sum );
}
if ( 0 < $total_sum_currency ) {
$get_order->update_meta_data( '_wfocu_upsell_amount_currency', $total_sum_currency );
}
$aid = WFOCU_Core()->data->get( 'fka_aid' );
$note = "Stripe recovery offer accepted.";
if ( ! empty( $aid ) && intval( $aid ) > 0 ) {
$note .= " Automation ID: " . $aid;
}
$get_order->add_order_note( $note );
/** Add item meta in the order */
$this->update_item_meta( $get_order );
if ( 0 < $total_sum || 0 < $total_sum_currency ) {
$get_order->save_meta_data();
}
global $wpdb;
$query = $wpdb->prepare( 'UPDATE`' . $wpdb->prefix . 'wfocu_session` SET `total` = %s WHERE `order_id` = %s', $total_sum, $get_current_order_id );
$wpdb->query( $query ); //phpcs:ignore
// db call ok; no-cache ok; unprepared SQL ok.
}
/**
* Helper method - Update item meta
*
* @param $order
*
* @return void
*/
protected function update_item_meta( $order ) {
if ( ! $order instanceof WC_Order ) {
return;
}
$items = $order->get_items();
if ( empty( $items ) ) {
return;
}
foreach ( $order->get_items() as $item ) {
$product = $item->get_product();
if ( ! $product instanceof WC_Product ) {
continue;
}
$item->add_meta_data( '_fk_automation_stripe_offer', 'yes', true );
$item->save_meta_data();
}
}
/**
* @param $arr
*
* @return array|mixed
*/
public function provide_pay_link_on_error( $arr ) {
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return $arr;
}
if ( WFOCU_Core()->public->failed_order !== null && isset( $arr['response'] ) && isset( $arr['response']['redirect_url'] ) ) {
$arr['response']['redirect_url'] = WFOCU_Core()->public->failed_order->get_checkout_payment_url();
}
return $arr;
}
/**
* Get upsell id by order id
*
* @param $order_id
*
* @return string|null
*/
public function get_upsell_id( $order_id ) {
global $wpdb;
$query = "SELECT `meta_value` FROM {$wpdb->prefix}wfocu_event_meta WHERE `event_id` = (SELECT `event_id` FROM {$wpdb->prefix}wfocu_event_meta WHERE `meta_key`='_new_order' AND `meta_value`=%d) AND `meta_key`='_funnel_id'";
return $wpdb->get_var( $wpdb->prepare( $query, $order_id ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param $thankyou_page_ids
* @param $order
*
* @return array
*/
public function maybe_filter_thankyou( $thankyou_page_ids, $order ) {
if ( ! $order instanceof WC_Order ) {
return $thankyou_page_ids;
}
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return $thankyou_page_ids;
}
$current_step = [];
$step_id = BWF_WC_Compatibility::get_order_meta( $order, '_wfocu_funnel_id' );
if ( empty( $step_id ) ) {
return $thankyou_page_ids;
}
if ( ! empty( $step_id ) && 0 !== abs( $step_id ) ) {
$funnel_id = get_post_meta( $step_id, '_bwf_in_funnel', true );
if ( ! empty( $funnel_id ) && abs( $funnel_id ) !== 0 ) {
$funnel = WFFN_Core()->admin->get_funnel( $funnel_id );
if ( $funnel instanceof WFFN_Funnel ) {
$current_step['id'] = $step_id;
$current_step['type'] = 'wc_upsells';
$get_type_object = WFFN_Core()->steps->get_integration_object( 'wc_thankyou' );
if ( $get_type_object instanceof WFFN_Step ) {
$thankyou_page_ids = $get_type_object->maybe_get_thankyou( $current_step, $funnel );
}
if ( empty( $thankyou_page_ids ) ) {
$thankyou_page_ids = $get_type_object->get_store_checkout_thankyou_page( $thankyou_page_ids, $order );
}
}
}
}
return $thankyou_page_ids;
}
/**
* Record thank you page views in upsell recovery
*
* @param $order_id
*
* @return void
*/
public function maybe_log_thankyou_visited( $order_id ) {
global $post;
$wfty_source = filter_input( INPUT_GET, 'wfty_source' );
if ( empty( $wfty_source ) || is_null( $post ) || ! class_exists( 'WFFN_Core' ) ) {
return;
}
/**
* Check valid upsell session
*/
if ( false === WFOCU_Core()->data->get_funnel_id() ) {
return;
}
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return;
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return;
}
$upsell_id = $order->get_meta( '_wfocu_funnel_id' );
if ( empty( $upsell_id ) ) {
return;
}
$funnel_id = get_post_meta( $upsell_id, '_bwf_in_funnel', true );
$funnel = new WFFN_Funnel( $funnel_id );
/**
* Check valid funnel session case
* Return if valid funnel because in upsell recovery has not funnel valid session
*/
if ( ! wffn_is_valid_funnel( $funnel ) || WFFN_Core()->data->has_valid_session() ) {
return;
}
WFCO_Model_Report_views::update_data( gmdate( 'Y-m-d', current_time( 'timestamp' ) ), $post->ID, 5 );
}
/**
* Upon offer reject, hook woocommerce thank you redirect code
*
* @return void
*/
public function redirect_to_home() {
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return;
}
remove_all_filters( 'woocommerce_get_checkout_order_received_url' );
add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'offer_rejected' ), 999999999 );
}
/**
* Return 0 offer id
* As don't want to show next offer
*
* @param $return
*
* @return int|mixed
*/
public function return_offer_zero( $return ) {
$created_via = WFOCU_Core()->data->get( 'created_via' );
if ( 'fka_stripe_offer' !== $created_via ) {
return $return;
}
return 0;
}
/**
* Change thank you url to home page in case of offer reject
*
* @return string|null
*/
public function offer_rejected() {
return home_url();
}
}
BWFAN_Generate_Offer_Link_Handler::get_instance();
}

View File

@@ -0,0 +1,194 @@
<?php
if ( ! class_exists( 'BWFAN_Generate_Offer_Link' ) ) {
class BWFAN_Generate_Offer_Link {
public $id = 0;
private $data = [];
public function __construct( $id = 0, $hash_code = '', $data = [] ) {
if ( intval( $id ) > 0 ) {
$this->data = BWFAN_Model_Stripe_Offer::get( $id );
}
if ( ! empty( $hash_code ) ) {
$db_data = BWFAN_Model_Stripe_Offer::get_specific_rows( 'hash_code', $hash_code );
$this->data = isset( $db_data[0] ) ? $db_data[0] : $this->data;
}
if ( ! empty( $data ) ) {
$this->set_data( $data );
}
}
/**
* @return mixed
*/
public function get_expiry_days() {
return $this->data['expiry_days'];
}
/**
* @return mixed
*/
public function get_create_date() {
return $this->data['created_at'];
}
/**
* @return array|mixed|object|stdClass|null
*/
public function get_data() {
return $this->data;
}
/**
* @param $data
*
* @return void
*/
public function set_data( $data ) {
foreach ( $data as $key => $value ) {
$this->data[ $key ] = $value;
}
if ( empty( $data['updated_at'] ) ) {
$this->data['updated_at'] = current_time( 'mysql' );
}
}
/**
* Generate upsell link
*
* @param $order_id
*
* @return string
*/
public function generate_upsell_link( $order_id ) {
if ( ! class_exists( 'WFOCU_Core' ) ) {
return '';
}
$order = wc_get_order( $order_id );
WFOCU_Core()->data->set( 'funnel_id', $this->data['fid'] );
$funnel_offers = WFOCU_Core()->offers->get_offers( $this->data['fid'] );
/** Get offer from funnel */
$offer_data = isset( $funnel_offers[ $this->data['oid'] ] ) ? $funnel_offers[ $this->data['oid'] ] : [];
if ( empty( $offer_data ) ) {
return '';
}
$offer = [ $this->data['oid'] => $offer_data ];
WFOCU_Core()->data->set( 'funnel', $offer );
/** Set flag and step id */
WFOCU_Core()->data->set( 'created_via', 'fka_stripe_offer' );
WFOCU_Core()->data->set( 'fka_upsell_created_at', $this->data['created_at'] );
WFOCU_Core()->data->set( 'fka_sid', $this->data['sid'] );
WFOCU_Core()->data->set( 'fka_p_key', $this->data['ID'] );
/** Set automation id if found in url query argument */
if ( isset( $_GET['automation_id'] ) && intval( $_GET['automation_id'] ) > 0 ) {
WFOCU_Core()->data->set( 'fka_aid', intval( $_GET['automation_id'] ) );
}
$ins = BWFAN_Generate_Offer_Link_Handler::get_instance();
remove_filter( 'wfocu_get_offer_id_filter', array( $ins, 'return_offer_zero' ), 1000000 );
$get_payment_gateway = WFOCU_WC_Compatibility::get_payment_gateway_from_order( $order );
$get_integration = WFOCU_Core()->gateways->get_integration( $get_payment_gateway );
$get_compatibility_class = WFOCU_Plugin_Compatibilities::get_compatibility_class( 'subscriptions' );
remove_filter( 'wfocu_front_payment_gateway_integration_enabled', array( $get_compatibility_class, 'maybe_disable_integration_when_subscription_in_cart' ), 10 );
$offer_url = '';
if ( WFOCU_Core()->data->is_funnel_exists() && $get_integration instanceof WFOCU_Gateway && $get_integration->is_enabled( $order ) && ( $get_integration->has_token( $order ) || $get_integration->is_run_without_token() ) ) {
$get_offer = WFOCU_Core()->offers->get_the_first_offer();
if ( 0 === absint( $get_offer ) ) { //integer check done
return $offer_url;
}
/**
* Check if parent order is same as the one saved in the session
* check if offer is the one saved in the session
* If both matches then we need to only return the upsell url we have and skip setting up upsell funnel again
*/
$get_order_id = WFOCU_Core()->data->get( 'porder', 0, 'orders' );
$get_current_offer = WFOCU_Core()->data->get( 'current_offer' );
if ( $get_order_id === WFOCU_WC_Compatibility::get_order_id( $order ) && ! empty( $get_current_offer ) && $get_current_offer === $get_offer ) {
return $this->get_the_upsell_url( $get_offer );
}
WFOCU_Core()->data->set( 'porder', $order, '_orders' );
WFOCU_Core()->data->set( 'porder', WFOCU_WC_Compatibility::get_order_id( $order ), 'orders' );
WFOCU_Core()->data->set( 'current_offer', $get_offer );
WFOCU_Core()->data->set( 'useremail', WFOCU_WC_Compatibility::get_order_data( $order, 'billing_email' ) );
WFOCU_Core()->data->save( 'orders' );
WFOCU_Core()->data->save();
do_action( 'wfocu_funnel_init_event', WFOCU_Core()->data->get_funnel_id(), 0, WFOCU_Core()->data->get( 'useremail' ), $order->get_payment_method(), $order->get_meta( '_woofunnel_cid' ) );
return $this->get_the_upsell_url( $get_offer );
}
return $offer_url;
}
/**
* Get upsell url
*
* @param $offer
*
* @return string
*/
public function get_the_upsell_url( $offer ) {
if ( empty( $offer ) ) {
return '';
}
$offer_data = WFOCU_Core()->offers->get_offer( $offer );
$link = WFOCU_Core()->offers->get_the_link( $offer );
if ( 'custom-page' === $offer_data->template ) {
$custom_page_id = get_post_meta( $offer, '_wfocu_custom_page', true );
if ( ! empty( $custom_page_id ) && intval( $custom_page_id ) > 0 ) {
$get_custom_page_post = get_post( $custom_page_id );
if ( is_null( $get_custom_page_post ) || ( is_object( $get_custom_page_post ) && 'publish' !== $get_custom_page_post->post_status ) ) {
return '';
}
}
}
return add_query_arg( array(
'wfocu-key' => WFOCU_Core()->data->get_funnel_key(),
'wfocu-si' => WFOCU_Core()->data->get_transient_key(),
), $link );
}
/**
* @return int|mixed
*/
public function save() {
if ( 0 === $this->get_id() ) {
BWFAN_Model_Stripe_Offer::insert( $this->data );
return BWFAN_Model_Stripe_Offer::insert_id();
}
$data = $this->data;
if ( isset( $data['ID'] ) ) {
unset( $data['ID'] );
}
BWFAN_Model_Stripe_Offer::update( $data, [ 'ID' => $this->get_id() ] );
return $this->id;
}
/**
* @return mixed
*/
public function get_id() {
$this->id = isset( $this->data['ID'] ) ? intval( $this->data['ID'] ) : 0;
return $this->id;
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class BWFAN_FK_Fetch_Bumps {
private static $ins = null;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function get_slug() {
return 'fk_fetch_bumps';
}
public function get_options( $search ) {
return BWFAN_PRO_Common::get_bumps( $search );
}
}
if ( class_exists( 'BWFAN_Load_Custom_Search' ) ) {
BWFAN_Load_Custom_Search::register( 'BWFAN_FK_Fetch_Bumps' );
}

View File

@@ -0,0 +1,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class BWFAN_FK_Fetch_Offers {
private static $ins = null;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function get_slug() {
return 'fk_fetch_offers';
}
public function get_options( $search ) {
return BWFAN_Pro_Common::get_offers( $search );
}
public static function get_data( $args, $search ) {
$posts = get_posts( $args );
$offers = [];
foreach ( $posts as $post ) {
$offers[ $post->ID ] = $post->post_title . '(#' . $post->ID . ')';
}
return array_filter( $offers, function ( $offer ) use ( $search ) {
return false !== strpos( strtolower( $offer ), strtolower( $search ) );
} );
}
}
if ( class_exists( 'BWFAN_Load_Custom_Search' ) ) {
BWFAN_Load_Custom_Search::register( 'BWFAN_FK_Fetch_Offers' );
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,204 @@
<?php
if ( ! class_exists( 'BWFAN_Stripe_Offer_Recovery_Link' ) ) {
class BWFAN_Stripe_Offer_Recovery_Link extends BWFAN_Merge_Tag {
private static $instance = null;
protected $support_v2 = true;
protected $support_v1 = false;
public function __construct() {
$this->tag_name = 'stripe_offer_recovery_link';
$this->tag_description = __( 'Offer Recovery Link', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_stripe_offer_recovery_link', array( $this, 'parse_shortcode' ) );
/** for getting the automation coupon step ids and their titles */
add_action( 'wp_ajax_bwfan_get_fka_upsell_recovery_options', array( $this, 'bwfan_get_fka_upsell_recovery_options' ) );
$this->priority = 25;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->parse_shortcode_output( $this->get_dummy_preview(), true );
}
$a_cid = BWFAN_Merge_Tag_Loader::get_data( 'automation_cid' );
$automation_id = BWFAN_Merge_Tag_Loader::get_data( 'automation_id' );
if ( empty( $a_cid ) ) {
/** when automation cid is not present i.e. old lite case */
$contact_id = BWFAN_Merge_Tag_Loader::get_data( 'cid' );
$contact_id = empty( $contact_id ) ? BWFAN_Merge_Tag_Loader::get_data( 'contact_id' ) : $contact_id;
$automation_contact_data = BWFAN_Model_Automation_Contact::get_automation_contact( $automation_id, $contact_id );
} else {
$automation_contact_data = BWFAN_Model_Automation_Contact::get_data( $a_cid );
}
if ( ! isset( $automation_contact_data['data'] ) || empty( $automation_contact_data['data'] ) ) {
return $this->parse_shortcode_output( '', $attr );
}
/** check for offer links */
$offer_link_data = json_decode( $automation_contact_data['data'], true );
if ( ! array_key_exists( 'offer_links', $offer_link_data ) || ! isset( $offer_link_data['offer_links'] ) ) {
return $this->parse_shortcode_output( '', $attr );
}
$step_id = $attr['sid'] ?? 0;
if ( empty( $step_id ) ) {
$step_id = array_key_first( $offer_link_data['offer_links'] );
}
/** check for step id */
if ( ! isset( $offer_link_data['offer_links'][ $step_id ] ) ) {
return $this->parse_shortcode_output( '', $attr );
}
$order_id = BWFAN_Merge_Tag_Loader::get_data( 'order_id' );
$offer_link_id = $offer_link_data['offer_links'][ $step_id ];
$link_data = BWFAN_Model_Stripe_Offer::get( $offer_link_id );
$hash_code = $link_data['hash_code'] ?? '';
$url = home_url();
if ( empty( $hash_code ) ) {
$this->parse_shortcode_output( $url, $attr );
}
$link = add_query_arg( array(
'bwfan-offer-code' => $hash_code,
'automation_id' => $automation_id,
'order_id' => $order_id
), $url );
return $this->parse_shortcode_output( $link, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return '';
}
/**
* will return the title of generate upsell recovery link in single automation
*
* @return void
*/
public function bwfan_get_fka_upsell_recovery_options() {
$finalarr = [];
$automationId = absint( sanitize_text_field( $_POST['automationId'] ) );
$merge_tag = isset( $_POST['merge_tag'] ) ? sanitize_text_field( $_POST['merge_tag'] ) : '';
/** check for automation id */
if ( empty( $automationId ) ) {
wp_send_json( array(
'results' => $finalarr
) );
exit;
}
global $wpdb;
/** To get automation step with action create coupon and stataus is 1 */
$query = "SELECT * FROM {$wpdb->prefix}bwfan_automation_step WHERE `aid` = {$automationId} AND `action` LIKE '%create_offer_recovery_link%' AND `status` = '1'";
$results = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
/** Check for empty step */
if ( empty( $results ) ) {
wp_send_json( array(
'results' => $finalarr,
) );
exit;
}
$automation_obj = BWFAN_Automation_V2::get_instance( $automationId );
/** Get automation meta data */
$automation_data = $automation_obj->get_automation_meta_data();
$mapped_arr = [];
/** Form mapped array with step id and node id */
foreach ( $automation_data['steps'] as $step ) {
if ( isset( $step['stepId'] ) ) {
$mapped_arr[ $step['stepId'] ] = $step['id'];
}
}
/** Iterating over resulting steps */
foreach ( $results as $data ) {
$stepid = $data['ID'];
$step_data = ( array ) json_decode( $data['data'], true );
/** Checking for title in upsell recovery link sidebar data */
if ( isset( $step_data['sidebarData'] ) && isset( $step_data['sidebarData']['title'] ) ) {
$link_title = $step_data['sidebarData']['title'] . ' ( #' . ( ! empty( $mapped_arr ) && isset( $mapped_arr[ $stepid ] ) ? $mapped_arr[ $stepid ] : $stepid ) . ' )';
} else {
$link_title = '#' . ( ! empty( $mapped_arr ) && isset( $mapped_arr[ $stepid ] ) ? $mapped_arr[ $stepid ] : $stepid );
}
if ( ! empty( $merge_tag ) ) {
$finalarr[] = [
'key' => '{{' . $this->tag_name . ' id="' . $stepid . '"}}',
'value' => $link_title,
];
} else {
$finalarr[] = [
'key' => $stepid,
'value' => $link_title,
];
}
}
wp_send_json( array(
'results' => $finalarr
) );
exit;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Return mergetag schema
*
* @return array[]
*/
public function get_setting_schema() {
return [
[
'id' => 'sid',
'type' => 'ajax',
'label' => __( 'Step ID', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"required" => true,
'placeholder' => 'Select',
"description" => "",
"ajax_cb" => 'bwfan_get_fka_upsell_recovery_options',
],
];
}
}
/**
* Register this merge tag to a group.
*/
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_builder_pro_active() && bwfan_is_fk_stripe_active() ) {
BWFAN_Merge_Tag_Loader::register( 'bwf_contact', 'BWFAN_Stripe_Offer_Recovery_Link', null, 'fk_stripe' );
}
}

View File

@@ -0,0 +1,121 @@
<?php
if ( ! class_exists( 'BWFAN_Rule_Stripe_offers' ) ) {
class BWFAN_Rule_Stripe_offers extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'stripe_offers' );
}
/** v2 Methods: START */
public function get_options( $search = '' ) {
return BWFAN_PRO_Common::get_offers( $search );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$offer_id = isset( $automation_data['global']['object_id'] ) ? $automation_data['global']['object_id'] : 0;
$offer_ids = array( $offer_id );
$selected_offers = array_map( function ( $offer ) {
return $offer['key'];
}, $rule_data['data'] );
$result = false;
switch ( $rule_data['rule'] ) {
case 'any':
if ( is_array( $selected_offers ) && is_array( $offer_ids ) ) {
$result = count( array_intersect( $selected_offers, $offer_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $selected_offers ) && is_array( $offer_ids ) ) {
$result = count( array_intersect( $selected_offers, $offer_ids ) ) === 0;
}
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
}
}
if ( ! class_exists( 'BWFAN_Stripe_Bumps' ) ) {
class BWFAN_Stripe_Bumps extends BWFAN_Rule_Base {
public function __construct() {
$this->v2 = true;
$this->v1 = false;
parent::__construct( 'stripe_bumps' );
}
/** v2 Methods: START */
public function get_options( $search = '' ) {
return BWFAN_PRO_Common::get_bumps( $search );
}
public function get_rule_type() {
return 'Search';
}
public function is_match_v2( $automation_data, $rule_data ) {
if ( ! isset( $automation_data['global'] ) || ! is_array( $automation_data['global'] ) ) {
return $this->return_is_match( false, $rule_data );
}
$bump_id = isset( $automation_data['global']['object_id'] ) ? $automation_data['global']['object_id'] : 0;
$bump_ids = array( $bump_id );
$selected_bumps = array_map( function ( $offer ) {
return $offer['key'];
}, $rule_data['data'] );
$result = false;
switch ( $rule_data['rule'] ) {
case 'any':
if ( is_array( $selected_bumps ) && is_array( $bump_ids ) ) {
$result = count( array_intersect( $selected_bumps, $bump_ids ) ) >= 1;
}
break;
case 'none':
if ( is_array( $selected_bumps ) && is_array( $bump_ids ) ) {
$result = count( array_intersect( $selected_bumps, $bump_ids ) ) === 0;
}
break;
}
return $this->return_is_match( $result, $rule_data );
}
public function get_possible_rule_operators() {
return array(
'any' => __( 'matches any of', 'wp-marketing-automations-pro' ),
'none' => __( 'matches none of', 'wp-marketing-automations-pro' ),
);
}
}
}