Orderadmin/assets/css/offer-refund-metabox.css 0000644 00000002724 14760024572 0014473 0 ustar 00 #wpfnl-offer-refund-metabox .inside {
padding: 0 0 12px;
margin: 0;
}
.wpfnl-order-refund-wrapper table tr th,
.wpfnl-order-refund-wrapper table tr td {
padding: 13px;
text-align: left;
}
.wpfnl-order-refund-wrapper table tr th {
background: #f8f8f8;
}
.wpfnl-order-refund-wrapper table tr th.wpfnl-item {
text-align: left;
}
.wpfnl-order-refund-wrapper table tr .thumb {
width: 60px;
}
.wpfnl-order-refund-wrapper table tr td img {
max-width: 100%;
height: auto;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-item {
min-width: 200px;
}
.wpfnl-order-refund-wrapper table tr td .wc-order-item-sku {
color: #888;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-offer-type {
width: 120px;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-cost {
width: 90px;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-quantity {
width: 70px;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-total {
width: 70px;
}
.wpfnl-order-refund-wrapper table tr td.wpfnl-action .button {
width: 80px;
text-align: center;
}
.wpfnl-order-refund-wrapper .no-refund-offer,
.wpfnl-order-refund-wrapper .refund-note {
background: #FFF9EB;
padding: 12px 14px;
border-left: 3px solid #FFB802;
margin: 0 13px;
color: #473D3D;
}
.wpfnl-refund-notice{
text-align: left;
background: #FFF9EB;
padding: 12px 14px;
border-left: 3px solid #FFB802;
margin: 0 13px;
color: #473D3D;
line-height: 1.5 !important;
} admin/assets/css/wpfnl-pro-admin.css 0000644 00000024255 14760024572 0013471 0 ustar 00 .wpfnl-license-page {
background: transparent;
}
.wpfnl-license-wrapper {
display: flex;
flex-flow: row wrap;
margin-top: 24px;
padding-right: 24px;
gap: 30px;
}
.wpfnl-license-wrapper .wpfnl-license-filed {
background: #FFFFFF;
box-shadow: 0px 1px 2px rgba(190, 190, 215, 0.2);
border-radius: 10px;
width: calc(100% - 390px);
padding: 15px 20px 20px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .product-title,
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title {
width: 390px;
position: relative;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .input-field,
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .input-field {
width: calc(100% - 460px);
max-width: 420px;
padding: 0 40px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .btn-area,
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .btn-area {
width: 170px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header {
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: space-between;
margin-bottom: 30px;
position: relative;
padding-bottom: 15px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header:before {
content: "";
position: absolute;
left: -20px;
bottom: 0;
width: calc(100% + 40px);
height: 1px;
background: #E5E8F3;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .single-field {
text-transform: uppercase;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
align-items: center;
width: 100%;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title {
display: flex;
align-items: center;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title .icon-info {
width: calc(100% - 50px);
padding-left: 15px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title h3 {
font-weight: 500;
font-size: 20px;
line-height: 23px;
color: #363B4E;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .license-status {
font-size: 14px;
line-height: 16px;
color: #7A8B9A;
margin-top: 5px;
display: block;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .addon-icon {
width: 50px;
height: 50px;
border-radius: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .input-field input {
height: 46px;
padding: 6px 15px 5px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .btn-area {
position: relative;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .btn-area .btn-default {
padding: 0 22px;
height: 46px;
min-width: 162px;
border-radius: 10px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .btn-area .lnc-notice {
color: green;
font-size: 15px;
text-transform: capitalize;
margin-left: 8px;
position: absolute;
bottom: -24px;
left: -4px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license {
padding: 15px;
background: #F7F7FA;
margin-top: 30px;
border-radius: 0 8px 8px 0;
border-left: 2px solid #6E42D3;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .single-addons {
margin-bottom: 15px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .single-addons:last-child {
margin-bottom: 0;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area {
padding: 12px 15px;
background-color: #fff;
box-shadow: 0px 1px 2px rgba(190, 190, 215, 0.2);
border-radius: 6px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .product-title {
width: 362px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .addon-icon {
background: #F7F7FA;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area h3 {
font-weight: 500;
font-size: 14px;
line-height: 1.1;
color: #363B4E;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .input-field input {
height: 38px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .btn-area {
width: 145px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .btn-area .btn-default {
padding: 0 18px;
font-size: 13px;
height: 38px;
min-width: auto;
margin-left: auto;
display: block;
border-radius: 6px;
width: 100%;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .not-get-addons .input-field-area .product-title {
width: calc(100% - 200px);
}
.wpfnl-license-wrapper .promo-text-area {
width: 360px;
background: #FFF;
border-radius: 10px;
box-shadow: 0px 1px 2px rgba(190, 190, 215, 0.2);
}
.wpfnl-license-wrapper .promo-text-area .single-area {
position: relative;
padding: 25px 25px 25px 90px;
background: #FFFFFF;
box-shadow: 0px 1px 2px rgba(190, 190, 215, 0.2);
border-radius: 10px;
margin-bottom: 30px;
}
.wpfnl-license-wrapper .promo-text-area .single-area:last-child {
margin-bottom: 0;
}
.wpfnl-license-wrapper .promo-text-area .single-area .icon {
background-color: #F7F7FA;
width: 50px;
height: 50px;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
border-radius: 100%;
position: absolute;
top: 30px;
left: 26px;
}
.wpfnl-license-wrapper .promo-text-area .single-area h4 {
font-size: 18px;
margin-bottom: 8px;
color: #363B4E;
font-weight: 500;
}
.wpfnl-license-wrapper .promo-text-area .single-area P {
font-size: 14px;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area {
padding: 20px;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
overflow: hidden;
height: 100%;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area .logo {
margin-bottom: 12px;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area p {
text-align: center;
margin-bottom: 20px;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area .btn-default {
height: 40px;
line-height: 40px;
position: relative;
z-index: 1;
}
.cl-doc-row {
display: flex;
flex-flow: row wrap;
margin-top: 30px;
padding-right: 24px;
gap: 30px;
}
.cl-doc-row .single-col {
background: #fff;
padding: 30px;
width: calc(25% - 23px);
border-radius: 8px;
display: flex;
flex-flow: column;
align-items: flex-start;
position: relative;
}
.cl-doc-row .single-col:last-child {
margin-right: 0;
}
.cl-doc-row .single-col .icon {
background-color: #f0f1f3;
width: 40px;
height: 40px;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
border-radius: 100%;
position: absolute;
top: 24px;
left: 30px;
}
.cl-doc-row .single-col h4 {
font-size: 20px;
margin-bottom: 22px;
font-weight: 500;
padding-left: 53px;
color: #3c434a;
}
.cl-doc-row .single-col p {
font-size: 14px;
margin-bottom: 20px;
}
.cl-doc-row .single-col .btn-default {
margin-top: auto;
}
.cl-doc-row .single-col.manage-license .icon svg {
width: 27px;
}
@media only screen and (min-width: 1400px) {
.cl-doc-row .single-col {
width: calc(33.3333333333% - 20px);
}
.cl-doc-row .single-col.manage-license {
display: none;
}
}
@media only screen and (max-width: 1620px) {
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .product-title,
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title {
width: 280px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .field-header .input-field,
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .input-field {
padding: 0 20px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .product-title {
width: 260px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .btn-area {
width: 150px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .input-field {
width: calc(100% - 410px);
}
}
@media only screen and (max-width: 1399px) {
.wpfnl-license-wrapper .wpfnl-license-filed {
width: 100%;
margin-right: 0;
}
.wpfnl-license-wrapper .promo-text-area {
width: 100%;
display: flex;
flex-flow: row wrap;
justify-content: center;
display: none;
}
.wpfnl-license-wrapper .promo-text-area .single-area {
width: calc(33.3333333333% - 20px);
margin-left: 30px;
margin-bottom: 0;
}
.wpfnl-license-wrapper .promo-text-area .single-area:first-child {
margin-left: 0;
}
.cl-doc-row .single-col {
padding: 25px 20px 20px;
}
.cl-doc-row .single-col .icon {
top: 17px;
left: 20px;
}
}
@media only screen and (max-width: 1199px) {
.wpfnl-license-wrapper {
gap: 20px;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area:before {
left: -47px;
}
.wpfnl-license-wrapper .promo-text-area .manage-license-area {
padding: 20px;
display: flex;
flex-flow: column;
justify-content: center;
}
.wpfnl-license-wrapper .promo-text-area .single-area {
width: calc(33.3333333333% - 14px);
margin-left: 20px;
padding: 20px;
}
.wpfnl-license-wrapper .promo-text-area .single-area .icon {
position: relative;
top: inherit;
left: inherit;
margin-bottom: 12px;
}
.cl-doc-row {
margin-top: 20px;
gap: 20px;
}
.cl-doc-row .single-col {
width: calc(50% - 10px);
}
.cl-doc-row .single-col .icon {
top: 18px;
left: 20px;
}
}
@media only screen and (max-width: 991px) {
.wpfnl-license-wrapper .wpfnl-license-filed .field-header {
display: none;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .product-title {
width: 100%;
margin-bottom: 10px;
}
.wpfnl-license-wrapper .wpfnl-license-filed .input-field-area .input-field {
width: calc(100% - 180px);
max-width: initial;
padding: 0;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .product-title {
width: 100%;
}
.wpfnl-license-wrapper .wpfnl-license-filed .addons-license .input-field-area .input-field {
width: calc(100% - 160px);
}
.cl-doc-row .single-col:nth-child(2) {
margin-right: 0;
}
}
/*# sourceMappingURL=wpfnl-pro-admin.css.map */
admin/assets/js/offer-refund-metabox.js 0000644 00000005722 14760024572 0014144 0 ustar 00 (function( $ ) {
'use strict';
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
$( '.button.wpfnl-offer-refund' ).on( 'click', function ( e ) {
e.preventDefault();
let refund_reason = prompt( 'Enter Refund reason', 'Refund WPFunnels Offer' );
if ( '' === refund_reason ) {
return alert( 'Please enter valid refund reason', false );
} else if ( null === refund_reason ) {
return false;
}
$('#wpfnl-offer-refund-metabox').block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var button = $(this),
order_id = button.attr( 'data-order-id' ),
step_id = button.attr( 'data-step-id' ),
item_id = button.attr( 'data-item-id' ),
product_id = button.attr( 'data-product-id' ),
qty = button.attr( 'data-item-quantity' ),
amount = button.attr( 'data-item-amount' ),
txn_id = button.attr( 'data-txn-id' );
var payload = {
order_id: order_id,
step_id: step_id,
product_id: product_id,
item_id: item_id,
quantity: qty,
amount: amount,
api_refund: true,
transaction_id: txn_id,
wpfnl_refund: true,
}
wpAjaxHelperRequest("wpfnl-refund-offer", payload)
.success(function(response) {
alert(response.msg);
$('#wpfnl-offer-refund-metabox').unblock();
window.location.reload();
})
.error(function(response) {
$('#wpfnl-offer-refund-metabox').unblock();
console.log(response)
});
});
$( '.refund-items' ).on( 'click', function ( e ) {
$('.wpfnl-refund-notice').remove();
$('.wc-order-refund-items').prepend('
Here, you can only refund the cost for the main product and order bump products.To refund products sold in Upsell & downsell, go to the WPFunnels Offers section.
')
});
})( jQuery ); admin/assets/js/wpfnl-pro-admin.js 0000644 00000002450 14760024572 0013132 0 ustar 00 (function( $ ) {
'use strict';
/**
* All the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered the best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
$( document ).on( 'click', 'div[data-notice_id="wpfnl-import-notice"] button.notice-dismiss', dismissFunnelImportNotice );
/**
* Create an ajax post request to hide funnel import notice.
*
* @since 1.9.7
*/
function dismissFunnelImportNotice() {
const payload = {
action: 'wpfnl_hide_import_funnel_notice',
security: WPFunnelProVars.admin_nonce
};
$.ajax({
type: 'POST',
dataType: 'json',
url: WPFunnelProVars.ajaxurl,
data: payload
});
}
})( jQuery );
admin/classes/class-wpfnl-order-meta.php 0000644 00000003600 14760024572 0014276 0 ustar 00 get_id();
$is_wpfnl_order = $order->get_meta('_wpfunnels_offer') === 'yes';
if( $is_wpfnl_order ) {
$parent_order_id = $order->get_meta('_wpfunnels_offer_parent_id');
if($parent_order_id) {
$parent_order_html = ''.__('Parent Order: ').'
';
$parent_order_html .= sprintf('#%2s', get_edit_post_link($parent_order_id), $parent_order_id);
echo $parent_order_html;
}
} else {
$child_order_html = '';
$child_orders = $order->get_meta( '_wpfunnels_offer_child_orders' );
if( $child_orders ) {
$child_order_html = ''.__('Offer orders: ').'';
foreach ($child_orders as $order_id => $child_order) {
$type = $child_order['type'];
$child_order_html .= sprintf('#%2s - %3s', get_edit_post_link($order_id), $order_id, $type);
}
$child_order_html .= '
';
}
echo $child_order_html;
}
}
} admin/classes/class-wpfnl-pro-notices.php 0000644 00000007331 14760024572 0014506 0 ustar 00 'inactive_license',
'inactive_supported_payment_gateway' => 'inactive_supported_payment_gateway',
);
public function __construct() {
foreach ( self::$core_notices as $notice ) {
add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
}
}
/**
* Inactive license notice
*/
public static function inactive_license() {
$disabled_notice_page = [
'edit_funnel',
'wp_funnels',
];
if( !isset($_GET['page']) || (isset($_GET['page']) && !in_array( $_GET['page'],$disabled_notice_page )) ) {
$active_status = get_option('wpfunnels_pro_license_status');
if( 'active' === $active_status ) {
return;
}
$message = sprintf( __( 'Your WPFunnels Pro License is not activate. Please, go to the WPFunnels > License menu and activate the license to use all the pro features of WPFunnels Pro . Activate now.', 'wpfnl-pro' ), esc_url(admin_url('admin.php?page=wpf-license')));
$output = '';
$output .= '
' . wp_kses_post( $message ) . '
';
$output .= '
';
echo $output;
}
}
/**
* Inactive supported payment gateway notice
*/
public static function inactive_supported_payment_gateway() {
$is_woocommerce = Wpfnl_functions::is_wc_active();
if( $is_woocommerce ){
global $post, $typenow, $current_screen;
$offer_settings = Wpfnl_functions::get_offer_settings();
if( is_admin() && 'wp_funnels' === $current_screen->parent_base && $offer_settings['show_supported_payment_gateway'] == 'on' ){
$available_payment_methods = WC()->payment_gateways->get_available_payment_gateways();
$supported_gateways = Payment_Gateways_Factory::getInstance()->get_supported_payment_gateways();
$is_supported_activated = false;
foreach($available_payment_methods as $key => $method ){
if( isset($supported_gateways[$key])){
$is_supported_activated = true;
}
}
if( !$is_supported_activated ){
$message = wp_sprintf( '%s - %l. %s %s',
__( 'You have selected the option to show only supported payment gateways in the funnel checkouts, but you do not have any supported payment gateways active. Please enable Stripe, Paypal, Mollie, Authorize.net, or Cash On Delivery.', 'wpfnl-pro' ),
'',
'Please check the supported gateways',
'https://getwpfunnels.com/docs/connect-payment-gateways/',
'here.'
);
$output = '';
$output .= '
' . wp_kses_post( $message ) . '
';
$output .= '
';
echo $output;
}else{
return;
}
}else{
return;
}
}
return;
}
} admin/classes/class-wpfnl-refund.php 0000644 00000017674 14760024572 0013542 0 ustar 00 handle('wpfnl-refund-offer')
->with_callback([ $this, 'refund_offer' ])
->with_validation($this->get_validation_data());
}
public function get_validation_data()
{
return [
'logged_in' => true,
'user_can' => 'wpf_manage_funnels',
];
}
/**
* register offer refund meta box
*/
public function order_refund_meta_box() {
global $post;
if ( 'shop_order' === get_current_screen()->id ) {
$this->order_id = $post->ID;
$order = wc_get_order($this->order_id);
if( false !== is_a( $order, 'WC_Order' ) ){
$funnel_id = $order->get_meta('_wpfunnels_funnel_id');
if( $funnel_id ) {
if($this->should_show_refund_metabox($order)) {
add_action( 'admin_enqueue_scripts', array( $this, 'add_offer_refund_scripts' ) );
add_meta_box(
'wpfnl-offer-refund-metabox',
__( 'WPFunnels Refund Offer', 'wpfnl-pro' ),
array( $this, 'refund_offer_metabox_callback' ),
'shop_order',
'normal'
);
add_filter( 'get_user_option_meta-box-order_shop_order', array( $this, 'move_refund_offer_metabox' ),10,1 );
}
}
}
}
}
/**
* move offer refund meta box under shop order
*
* @param $metabox
* @return mixed
*/
public function move_refund_offer_metabox( $metabox ) {
$metabox['normal'] = join( ',', array(
'woocommerce-order-items',
'wpfnl-offer-refund-metabox',
) );
return $metabox;
}
/**
* add scripts for refund meta box
*/
public function add_offer_refund_scripts() {
if ( ! is_admin() ) {
return;
}
wp_enqueue_style( 'wpfnl-pro-offer-refund', WPFNL_PRO_URL . 'admin/assets/css/offer-refund-metabox.css', array(), WPFNL_PRO_VERSION );
wp_enqueue_script( 'wpfnl-pro-offer-refund', WPFNL_PRO_URL . 'admin/assets/js/offer-refund-metabox.js', array( 'jquery' ), WPFNL_PRO_VERSION, true );
}
/**
* should show refund meta
*
* @param \WC_Order $order
* @return bool
*/
public function should_show_refund_metabox( \WC_Order $order ) {
$is_offer_exists = $this->is_offer_exits_in_order($order);
if($is_offer_exists) {
$order_gateway = $order->get_payment_method();
$payment_gateway_obj = Wpfnl_Pro::instance()->payment_gateways->build_gateway($order_gateway);
$is_refund_supported = $payment_gateway_obj->refund_support;
if($is_refund_supported) {
return true;
}
}
return false;
}
/**
* check if offer exits in order
*
* @param \WC_Order $order
* @return bool
*/
private function is_offer_exits_in_order( \WC_Order $order ) {
$is_offer = false;
$line_items = $order->get_items();
foreach ($line_items as $item_id => $item) {
$is_upsell_offer = wc_get_order_item_meta( $item_id, '_wpfunnels_upsell', true );
$is_downsell_offer = wc_get_order_item_meta( $item_id, '_wpfunnels_downsell', true );
$txn_id = wc_get_order_item_meta( $item_id, '_wpfunnels_offer_txn_id', true );
if ( 'yes' == $is_upsell_offer || 'yes' == $is_downsell_offer && ! empty( $txn_id ) ) {
$is_offer = true;
break;
}
}
return $is_offer;
}
public function refund_offer_metabox_callback() {
include WPFNL_PRO_DIR . 'admin/partials/refund-metabox.php';
}
/**
* refund offer ajax action
*
* @param $payload
* @return array
* @throws \Exception
*/
public function refund_offer($payload) {
$order_id = isset( $payload['order_id'] ) ? intval( $payload['order_id'] ) : 0;
$step_id = isset( $payload['step_id'] ) ? intval( $payload['step_id'] ) : 0;
$product_id = isset( $payload['product_id'] ) ? intval( $payload['product_id'] ) : 0;
$quantity = isset( $payload['quantity'] ) ? $payload['quantity'] : 0;
$amount = isset( $payload['amount'] ) ? $payload['amount'] : 0;
$api_refund = isset( $payload['api_refund'] ) ? $payload['api_refund'] : false;
$transaction_id = isset( $payload['transaction_id'] ) ? $payload['transaction_id'] : '';
$item_id = isset( $payload['item_id'] ) ? $payload['item_id'] : '';
$wpfnl_refund = isset( $payload['wpfnl_refund'] ) ? $payload['wpfnl_refund'] : '';
$refund_reason = isset( $payload['refund_reason'] ) ? $payload['refund_reason'] : '';
$data = array(
'offer_id' => $product_id,
'transaction_id' => $transaction_id,
'amount' => $amount,
'step_id' => $step_id,
'reason' => '',
);
$result = array(
'success' => false,
'msg' => __( 'Refund unsuccessful', 'wpfnl-pro' ),
);
if( $order_id ) {
$order = wc_get_order($order_id);
$order_gateway = $order->get_payment_method();
$payment_gateway_obj = Wpfnl_Pro::instance()->payment_gateways->build_gateway($order_gateway);
if( $payment_gateway_obj->refund_support ) {
$refunded_txn_id = $payment_gateway_obj->process_refund_offer( $order, $data );
}
if ( false !== $refunded_txn_id ) {
$offer_item = WC_Order_Factory::get_order_item( $item_id );
$line_items[ $item_id ] = array(
'qty' => max( $offer_item->get_quantity(), 0 ),
'refund_total' => wc_format_decimal( $offer_item->get_total() ),
'refund_tax' => array(),
);
$order_taxes = $order->get_taxes();
$tax_data = $offer_item->get_taxes();
$tax_item_total = [];
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total[ $tax_item_id ] = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : 0;
}
$line_items[ $item_id ]['refund_tax'] = array_filter( array_map( 'wc_format_decimal', $tax_item_total ) );
$refund = wc_create_refund(
array(
'amount' => $amount,
'reason' => $refund_reason,
'order_id' => $order_id,
'refund_payment' => false,
'line_items' => $line_items,
'restock_items' => true,
)
);
if ( is_wp_error( $refund ) ) {
$result['success'] = true;
$result['msg'] = __( 'Refund Unsuccessful', 'wpfnl-pro' );
} else {
wc_update_order_item_meta( $item_id, '_wpfunnels_offer_refunded', 'yes' );
$result['success'] = true;
$result['msg'] = __( 'Refund Successful', 'wpfnl-pro' );
}
}
}
return $result;
}
} admin/modules/ab-testing/class-wpfnl-ab-testing-hook-backup.php 0000644 00000042466 14760024572 0020562 0 ustar 00 $step){
$node_data = isset($step['data']) ? $step['data'] : [];
if( isset($node_data['step_id']) ){
$ab_testings_settings = Backup_Ab_Testing::get_formatted_settings( $node_data['step_id'] );
$class = $step['class'];
$triggers = Wpfnl_functions::get_mint_triggers();
$actions = Wpfnl_functions::get_mint_actions();
if( in_array( $node_data['step_type'], $triggers ) ){
$class = $class.' mint-trigger-action mint-trigger';
$step_data[$key]['class'] = $class;
}
if( in_array( $node_data['step_type'], $actions ) ){
$class = $class.' mint-trigger-action mint-action';
$step_data[$key]['class'] = $class;
}
if( isset($ab_testings_settings['data']['start_settings']['variations']) && count($ab_testings_settings['data']['start_settings']['variations']) > 1 ) {
$needle = 'has-ab-variation';
if (strpos($class, $needle) === false) {
$step_data[$key]['class'] = $class.' has-ab-variation';
}
}else{
$needle = 'has-ab-variation';
if (strpos($class, $needle) !== false) {
$step_data[$key]['class'] = trim(str_replace('has-ab-variation','',$class));
}
}
}
}
}
return $step_data;
}
/**
* set ab testing winner
* @param Int $funnel_id
* @param Int $step_id
*
* @return void
* @since 1.7.1
*/
public function update_ab_testing_winner( $funnel_id, $step_id ){
$parent_step_id = Backup_Ab_Testing::get_parent_step_id( $step_id ) ? Backup_Ab_Testing::get_parent_step_id( $step_id ) : $step_id;
$is_enable = Backup_Ab_Testing::maybe_ab_testing( $parent_step_id );
if( $is_enable ){
$all_conditions = Backup_Ab_Testing::get_all_conditions( $parent_step_id );
$is_matched = Backup_Ab_Testing::match_condition( $all_conditions, $funnel_id, $parent_step_id );
$is_winner = Backup_Ab_Testing::get_winner( $parent_step_id );
if( !$is_winner && $is_matched ){
Backup_Ab_Testing::set_winner( $parent_step_id, $step_id );
// stop AB testing after winner matched
$data = get_post_meta( $parent_step_id, '_wpfnl_ab_testing_start_settings' , true );
$data['start_date'] = date( 'Y-m-d H:i:s' );
$data['is_started'] = '';
Backup_Ab_Testing::update_start_settings( $parent_step_id, $data );
}
}
}
/**
* Update funnel view link when ab testings is activated
* @param String $link
* @param Int $step_id
* @param Int $funnel_id
*/
public function modify_funnel_view_link( $link, $step_id, $funnel_id ){
if (class_exists('\WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing')) {
$instance = new \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
$function_exist = is_callable(array($instance, 'maybe_ab_testing'));
if( $function_exist ){
$is_enabled = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::maybe_ab_testing( $step_id );
$variations = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_all_variations( $step_id );
if( 'yes' == $is_enabled && count($variations) > 1 ){
$link = get_the_permalink($funnel_id).'?wpfnl-step-id='.$step_id;
}
}
}
return $link;
}
/**
* Update the meta information for a step in a funnel.
*
* This function updates the meta information, such as the post title, post name (slug),
* step title, and step view link for a specific step in a funnel. It utilizes the
* Wpfnl_Ab_Testing class from the WPFunnelsPro\AbTesting namespace to handle the update.
*
* @param int $step_id The ID of the step to update.
* @param int $funnel_id The ID of the funnel to which the step belongs.
* @param array $settings An array of settings containing the title and slug for the step.
* @return void
* @since 1.7.1
*/
public function update_step_meta( $step_id, $funnel_id, $settings ){
$instance = new \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
$function_exist = is_callable(array($instance, 'get_formatted_settings'));
if( $function_exist ){
$parent_step_id = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_parent_step_id( $step_id );
$parent_step_id = $parent_step_id ? $parent_step_id : $step_id;
$ab_settings = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_formatted_settings( $parent_step_id );
if( is_array($ab_settings) && isset($ab_settings['data']['start_settings']['variations']) ){
update_post_meta( $step_id, '_wpf_step_title', $settings['title'] );
update_post_meta( $step_id, '_wpf_step_slug', $settings['slug'] );
wp_update_post([
"ID" => $step_id,
"post_title" => wp_strip_all_tags( $settings['title'] ),
"post_name" => sanitize_title($settings['slug']),
]);
foreach( $ab_settings['data']['start_settings']['variations'] as $key=>$variation ){
if( $variation['id'] == $step_id ){
$ab_settings['data']['start_settings']['variations'][$key]['step_title'] = htmlspecialchars_decode(get_the_title($step_id));
$ab_settings['data']['start_settings']['variations'][$key]['step_view_link'] = rtrim( get_the_permalink($step_id), '/' );
}
}
$ab_settings = $ab_settings['data']['start_settings'];
\WPFunnelsPro\AbTesting\Backup_Ab_Testing::update_start_settings( $parent_step_id, $ab_settings );
}
}
}
/**
* Update the meta information for a step in a funnel on funnel name change.
*
*
* @param int $step_id The ID of the step to update.
* @param int $funnel_id The ID of the funnel to which the step belongs.
* @param array $settings An array of settings containing the title and slug for the step.
* @return void
* @since 1.7.1
*/
public function update_step_meta_on_funnel_name_change( $step_id, $funnel_id, $settings ){
$instance = new \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
$function_exist = is_callable(array($instance, 'get_formatted_settings'));
if( $function_exist ){
$parent_step_id = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_parent_step_id( $step_id );
$parent_step_id = $parent_step_id ? $parent_step_id : $step_id;
$ab_settings = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_formatted_settings( $parent_step_id );
if( is_array($ab_settings) && isset($ab_settings['data']['start_settings']['variations']) ){
wp_update_post([
"ID" => $parent_step_id,
"post_title" => wp_strip_all_tags( $settings['title'] ),
"post_name" => sanitize_title($settings['slug']),
]);
foreach( $ab_settings['data']['start_settings']['variations'] as $key=>$variation ){
if( $variation['id'] == $step_id ){
$ab_settings['data']['start_settings']['variations'][$key]['step_title'] = htmlspecialchars_decode(get_the_title($parent_step_id));
$ab_settings['data']['start_settings']['variations'][$key]['step_view_link'] = rtrim( get_the_permalink($parent_step_id), '/' );
}
}
$ab_settings = $ab_settings['data']['start_settings'];
\WPFunnelsPro\AbTesting\Backup_Ab_Testing::update_start_settings( $parent_step_id, $ab_settings );
}
}
}
/**
* update funnel data response
*
* @param Array $response
*
* @since 1.7.2
* @return Array $response
*/
public function update_funnel_data_response( $response ){
$ab_data = [];
if( is_array($response) && !empty($response['funnel_data']['drawflow']['Home']['data']) ){
$steps_order = $response['funnel_data']['drawflow']['Home']['data'];
if( is_array($steps_order) ){
foreach( $steps_order as $key=>$step ){
if( isset( $step['data']['step_id'] ) ){
$step_id = $step['data']['step_id'];
$default_settings = Backup_Ab_Testing::get_default_start_setting( $step_id );
//check A/B testing is enable or not
$result = Backup_Ab_Testing::maybe_ab_testing( $step_id );
$default_settings['is_ab_enabled'] = $result ? $result : '';
// get start settings
$result = Backup_Ab_Testing::get_start_settings( $step_id );
$default_settings['start_settings'] = $result ? $result : $default_settings['start_settings'];
if( isset($default_settings['start_settings']['variations']) && is_array($default_settings['start_settings']['variations']) ){
foreach( $default_settings['start_settings']['variations'] as $key => $variation ){
if( isset($variation['id'], $variation['step_type']) && ( 'checkout' == $variation['step_type'] || 'upsell' == $variation['step_type'] || 'downsell' == $variation['step_type'])){
$step_products = get_post_meta( $variation['id'], '_wpfnl_'.$variation['step_type'].'_products', true );
if( is_array($step_products) && count($step_products) ){
$default_settings['start_settings']['variations'][$key]['is_product'] = 'yes';
}
if( 'checkout' == $variation['step_type'] ){
$ob_products = get_post_meta( $variation['id'], 'order-bump-settings', true );
if( is_array($ob_products) && count($ob_products) ){
$default_settings['start_settings']['variations'][$key]['is_ob'] = 'yes';
}
}
}
if( count($default_settings['start_settings']['variations']) > 1 ){
$funnel_id = get_post_meta( $variation['id'], '_funnel_id', true );
$stats = Backup_Ab_Testing::get_stats_of_a_step( $funnel_id, $variation['id'] );
if( isset($stats['total_visit'], $stats['conversion'] ) ){
$default_settings['start_settings']['variations'][$key]['visit'] = $stats['total_visit'];
$default_settings['start_settings']['variations'][$key]['conversion'] = $stats['conversion'];
}
}else{
foreach( $response['steps_order'] as $step_order ){
if( isset( $step_order['id'], $variation['id'] ) && $variation['id'] == $step_order['id'] ){
$default_settings['start_settings']['variations'][$key]['visit'] = $step_order['visit'];
$default_settings['start_settings']['variations'][$key]['conversion'] = $step_order['conversion'];
}
}
}
}
}
$ab_data['step_'.$step_id]['data'] = $default_settings;
$ab_data['step_'.$step_id]['step_type'] = get_post_meta( $step_id, '_step_type', true );
}
}
}
}
$response['ab_data'] = $ab_data;
return $response;
}
/**
* Update funnel link
*
* @param Array $response
*
* @return Array $response
* @since 1.7.4
*/
public function update_funnel_link( $response ){
if (class_exists('\WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing')) {
$instance = new \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
$function_exist = is_callable(array($instance, 'maybe_ab_testing'));
if( $function_exist ){
if( isset($response['funnel_id'],$response['step_id']) ){
$is_enabled = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::maybe_ab_testing( $response['step_id'] );
$variations = \WPFunnelsPro\AbTesting\Backup_Ab_Testing::get_all_variations( $response['step_id'] );
if( 'yes' == $is_enabled && count($variations) > 1 ){
$utm_settings = Wpfnl_functions::get_funnel_utm_settings( $response['funnel_id'] );
if($utm_settings['utm_enable'] == 'on') {
unset($utm_settings['utm_enable']);
$view_link = add_query_arg($utm_settings,get_the_permalink($response['funnel_id']));
$view_link = strtolower($view_link);
$response['link'] = $view_link;
}
$args = [
'wpfnl-step-id' => $response['step_id'],
];
$response['link'] = add_query_arg($args,$response['link']);
}
}
}
}
return $response;
}
}
admin/modules/ab-testing/class-wpfnl-ab-testing-hook.php 0000644 00000034661 14760024572 0017315 0 ustar 00 $parent_step_id,
"post_title" => wp_strip_all_tags( $settings['title'] ),
"post_name" => sanitize_title($settings['slug']),
]);
foreach( $ab_settings['data']['start_settings']['variations'] as $key=>$variation ){
if( $variation['id'] == $step_id ){
$ab_settings['data']['start_settings']['variations'][$key]['step_title'] = htmlspecialchars_decode(get_the_title($parent_step_id));
$ab_settings['data']['start_settings']['variations'][$key]['step_view_link'] = rtrim( get_the_permalink($parent_step_id), '/' );
}
}
$ab_settings = $ab_settings['data']['start_settings'];
\WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing::update_start_settings( $parent_step_id, $ab_settings );
}
}
}
/**
* update funnel data response
*
* @param Array $response
*
* @since 1.7.2
* @return Array $response
*/
public function update_funnel_data_response( $response ){
if( is_array($response) && !empty($response['funnel_data']['drawflow']['Home']['data']) ){
$steps_order = $response['funnel_data']['drawflow']['Home']['data'];
if( is_array($steps_order) ){
foreach( $steps_order as $key=>$step ){
if( isset( $step['data']['step_id'], $response['funnel_data']['drawflow']['Home']['data'][$key]['data']['step_view_link'] ) ){
$step_id = $step['data']['step_id'];
if( Wpfnl_Ab_Testing::maybe_ab_testing_running( $step_id ) ){
$url = base64_decode($response['funnel_data']['drawflow']['Home']['data'][$key]['data']['step_view_link']);
if( false === strpos($url, '?wpfnl-step-id') ){
$response['funnel_data']['drawflow']['Home']['data'][$key]['data']['step_view_link'] = base64_encode(base64_decode($step['data']['step_view_link']).'?wpfnl-step-id='.$step_id);
}
}else{
$url = base64_decode($response['funnel_data']['drawflow']['Home']['data'][$key]['data']['step_view_link']);
if( false !== strpos($url, '?wpfnl-step-id') ){
$response['funnel_data']['drawflow']['Home']['data'][$key]['data']['step_view_link'] = base64_encode($this->remove_query_param( $url, 'wpfnl-step-id' ));
}
}
}
}
}
}
return $response;
}
private function remove_query_param($url, $paramToRemove) {
// Parse the URL into components
$urlParts = parse_url($url);
if(isset($urlParts['query'])) {
// Parse the query string into an array
parse_str($urlParts['query'], $queryParams);
// Remove the specified parameter
if(isset($queryParams[$paramToRemove])) {
unset($queryParams[$paramToRemove]);
}
// Rebuild the query string
$newQuery = http_build_query($queryParams);
// Reconstruct the URL
$newUrl = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
if (!empty($newQuery)) {
$newUrl .= '?' . $newQuery;
}
if(isset($urlParts['fragment'])) {
$newUrl .= '#' . $urlParts['fragment'];
}
return $newUrl;
} else {
// No query parameters, return the original URL
return $url;
}
}
/**
* Update funnel link
*
* @param Array $response
*
* @return Array $response
* @since 1.7.4
*/
public function update_funnel_link( $response ){
if (class_exists('\WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing')) {
$instance = new \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
$function_exist = is_callable(array($instance, 'maybe_ab_testing'));
if( $function_exist ){
if( isset($response['funnel_id'],$response['step_id']) ){
$is_enabled = \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing::maybe_ab_testing( $response['step_id'] );
$variations = \WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing::get_all_variations( $response['step_id'] );
if( 'yes' == $is_enabled && count($variations) > 1 ){
$utm_settings = Wpfnl_functions::get_funnel_utm_settings( $response['funnel_id'] );
if($utm_settings['utm_enable'] == 'on') {
unset($utm_settings['utm_enable']);
$view_link = add_query_arg($utm_settings,get_the_permalink($response['funnel_id']));
$view_link = strtolower($view_link);
$response['link'] = $view_link;
}
$args = [
'wpfnl-step-id' => $response['step_id'],
];
$response['link'] = add_query_arg($args,$response['link']);
}
}
}
}
return $response;
}
/**
* update step data if ab testings enable
*
* @param array $step_data
* @param int $step_id
*
* @return array $step_data
* @since 2.0.0
*/
public function update_step_data( $step_data, $step_id ){
if( !$step_id ){
return $step_data;
}
$maybe_ab_testing = Wpfnl_Ab_Testing::maybe_ab_testing_running($step_id);
$step_data['maybe_ab_testing'] = $maybe_ab_testing ? 'yes' : 'no';
return $step_data;
}
/**
* Update the meta information for a step in a funnel.
*
* This function updates the meta information, such as the post title, post name (slug),
* step title, and step view link for a specific step in a funnel. It utilizes the
* Wpfnl_Ab_Testing class from the WPFunnelsPro\AbTesting namespace to handle the update.
*
* @param int $step_id The ID of the step to update.
* @param int $funnel_id The ID of the funnel to which the step belongs.
* @param array $settings An array of settings containing the title and slug for the step.
* @return void
* @since 1.7.1
*/
public function update_step_meta( $step_id, $funnel_id, $settings ){
$parent_id = get_post_meta( $step_id, '_parent_step_id', true );
$ab_settings = get_post_meta( $parent_id, '_wpfnl_ab_testing_start_settings', true );
if( isset($ab_settings['variations']) && is_array($ab_settings['variations']) ){
foreach( $ab_settings['variations'] as $key=>$variation ){
if( $variation['stepId'] == $step_id ){
$ab_settings['variations'][$key]['stepName'] = htmlspecialchars_decode(get_the_title($step_id));
$ab_settings['variations'][$key]['stepViewLink'] = rtrim( get_the_permalink($step_id), '/' );
}
}
update_post_meta( $parent_id, '_wpfnl_ab_testing_start_settings', $ab_settings );
}
}
/**
* Runs the scheduler for A/B testing.
*
* @param int $step_id The ID of the step.
* @param array $settings The settings for the A/B testing.
*
* @since 2.2.6
*/
public function run_scheduler($step_id,$settings){
if( !$step_id || !isset($settings['autoEnd']) || 'yes' != $settings['autoEnd'] || !isset($settings['endDate']) || !$settings['endDate']){
return;
}
$data['data'] = $step_id;
$time = strtotime($settings['endDate']);
$group = 'wpfnl-ab-testing-'.$step_id;
Wpfnl_Ab_Testing::delete_as_actions($group);
if ( function_exists('as_has_scheduled_action') ) {
$data['data'] = $step_id;
as_schedule_single_action( $time, 'wpfnl_auto_end_ab_testing', $data, $group);
}elseif( function_exists('as_next_scheduled_action') ){
if ( false === as_next_scheduled_action( 'wpfnl_auto_end_ab_testing' ) ) {
$data['data'] = $step_id;
as_schedule_single_action( $time, 'wpfnl_auto_end_ab_testing', $data, $group );
}
}
}
/**
* Process automation data from Cookie and initiate triggers
*
* @param $data
* @retun null
*
* @since 2.2.6
*/
public function wpfnl_auto_end_ab_testing( $step_id ) {
$settings = get_post_meta( $step_id, 'wpfnl_ab_testing_general_settings', true );
if( isset( $settings['autoEndSettings']['autoEnd'] )){
$settings['autoEndSettings']['autoEnd'] = 'no';
update_post_meta( $step_id, 'wpfnl_ab_testing_general_settings', $settings );
}
Wpfnl_Ab_Testing::update_running_status( $step_id,'no' );
}
}
admin/modules/mint/class-wpfnl-mint-hook-backup.php 0000644 00000021457 14760024572 0016403 0 ustar 00 $step ){
if( isset( $step['data']['step_id'] ) ){
$step_id = $step['data']['step_id'];
if( Wpfnl_functions::is_mint_mrm_active() ){
$automation = get_post_meta( $step_id, '_wpfnl_automation_steps', true );
if( is_array($automation) ){
$key = array_search('sendMail', array_column($automation, 'key'));
if( false !== $key ){
if( isset($automation[$key]['settings']['settings']['message_data']['body']) ){
unset($automation[$key]['settings']['settings']['message_data']['body']);
}
}
}
$automation_steps['step_'.$step_id]['data'] = $automation ? $automation : [];
}
}
}
}
}
$response['automationSteps'] = $automation_steps;
return $response;
}
/**
* Save mint automation settings
*
* @param int $funnel_id
* @param array $automation_steps
*/
public function save_mint_automation( $funnel_id, $automation_steps ){
if( $automation_steps && is_array($automation_steps) ){
foreach( $automation_steps as $key=>$step ){
if( !empty($step['stepID']) ){
$data = isset($step['value']) ? $step['value'] : [];
$step_data = get_post_meta( $step['stepID'], '_wpfnl_automation_steps', true );
$key = array_search('sendMail', array_column($data, 'key'));
if( false !== $key && isset($data[$key]['settings']['settings']['message_data']['body']) && isset($step_data[$key]['settings']['settings']['message_data']['body']) ){
$data[$key]['settings']['settings']['message_data']['body'] = $step_data[$key]['settings']['settings']['message_data']['body'];
}
update_post_meta( $step['stepID'], '_wpfnl_automation_steps', $data );
}
}
}
}
/**
* Delete funnel automation
*
* @param int $funnel_id
*/
public function delete_funnel_automation( $funnel_id ){
if( Wpfnl_functions::is_mint_mrm_active() ){
Wpfnl_Pro_functions::delete_automation_by_funnel_id( $funnel_id );
}
}
/**
* Delete funnel automation
*
* @param int $funnel_id
*/
public function maybe_automation_exist_for_a_funnel( $response, $funnel_id ){
if( Wpfnl_functions::is_mint_mrm_active() && class_exists("Mint\\MRM\\DataBase\\Tables\\AutomationMetaSchema") && class_exists("MintMail\\App\\Internal\\Automation\\AutomationModel") && class_exists("Mint\\MRM\\DataBase\\Tables\\AutomationSchema") ) {
$automationSchema = "Mint\\MRM\\DataBase\\Tables\\AutomationSchema";
$automationMetaSchema = "Mint\\MRM\\DataBase\\Tables\\AutomationMetaSchema";
global $wpdb;
$automation_table = $wpdb->prefix . $automationSchema::$table_name;
$automation_meta_table = $wpdb->prefix . $automationMetaSchema::$table_name;
$automations = $wpdb->get_results( $wpdb->prepare( "SELECT automation.id as id FROM $automation_table as automation INNER JOIN $automation_meta_table as automation_meta ON automation.id = automation_meta.automation_id WHERE automation_meta.meta_key = %s AND automation_meta.meta_value = %s", array( 'funnel_id', $funnel_id ) ), ARRAY_A ); // db call ok. ; no-cache ok.
if( is_array($automations) && count($automations) ){
$response = true;
}
}
return $response;
}
/**
* Create a MainMint contact if conditions are met.
*
* This function checks if certain conditions are met and if the required classes
* exist. If the conditions are satisfied, it creates a new contact in the MainMint
* system with the provided email address and automation ID. This process may involve
* sending a double-opt-in email if configured.
*
* @since 1.9.6
*
* @param int $automation_id The ID of the automation.
* @param string $email The email address of the contact to be created.
*
* @return void
*/
public function maybe_create_mainmint_contact( $automation_id, $email ) {
if ( $automation_id && $email &&
class_exists( 'Mint\\MRM\\DataBase\\Tables\\AutomationMetaSchema' ) &&
class_exists( 'MintMail\\App\\Internal\\Automation\\AutomationModel' ) &&
class_exists( 'Mint\\MRM\\DataBase\\Tables\\AutomationSchema' )
) {
$is_exist = $this->maybe_automation_exist( $automation_id );
if ( $is_exist ) {
if ( !HelperFunctions::maybe_user( $email ) ) {
$is_double_optin = MRMCommon::is_double_optin_enable();
$parms = array(
'status' => $is_double_optin ? 'pending' : 'subscribed',
);
$contact = new ContactData( $email, $parms );
$contact_id = ContactModel::insert( $contact );
if ( $contact_id && $is_double_optin ) {
MessageController::get_instance()->send_double_opt_in( $contact_id );
}
}
}
}
}
/**
* Check if a specific automation exists.
*
* This private function checks whether a given automation ID exists in the MainMint
* system by querying the appropriate tables. It uses the provided automation ID to
* look for matching automations based on predefined conditions.
*
* @since 1.6.0
*
* @param int $automation_id The ID of the automation to check.
*
* @return bool True if the automation exists, false otherwise.
*/
private function maybe_automation_exist( $automation_id ) {
if ( ! $automation_id ) {
return false;
}
global $wpdb;
$automation_table = $wpdb->prefix . 'mint_automations';
$automation_meta_table = $wpdb->prefix . 'mint_automation_meta';
// Query to retrieve matching automations.
$automations = $wpdb->get_results(
$wpdb->prepare(
"SELECT automation.id as id
FROM $automation_table as automation
INNER JOIN $automation_meta_table as automation_meta
ON automation.id = automation_meta.automation_id
WHERE automation_meta.automation_id = %d
AND automation_meta.meta_key = %s
AND automation_meta.meta_value = %s",
array( $automation_id, 'source', 'wpf' )
),
ARRAY_A
);
if ( ! is_array( $automations ) || ! count( $automations ) ) {
return false;
}
return true;
}
} admin/modules/mint/class-wpfnl-mint-hook.php 0000644 00000015374 14760024572 0015141 0 ustar 00 prefix . $automationSchema::$table_name;
$automation_meta_table = $wpdb->prefix . $automationMetaSchema::$table_name;
$automations = $wpdb->get_results( $wpdb->prepare( "SELECT automation.id as id FROM $automation_table as automation INNER JOIN $automation_meta_table as automation_meta ON automation.id = automation_meta.automation_id WHERE automation_meta.meta_key = %s AND automation_meta.meta_value = %s", array( 'funnel_id', $funnel_id ) ), ARRAY_A ); // db call ok. ; no-cache ok.
if( is_array($automations) && count($automations) ){
$response = true;
}
}
return $response;
}
/**
* update step data if mint automation enable
*
* @param array $step_data
* @param int $step_id
*
* @return array $step_data
* @since 2.0.0
*/
public function update_step_data( $step_data, $step_id ){
if( !$step_id ){
return $step_data;
}
$trigger = get_post_meta( $step_id, '_wpfnl_automation_trigger', true );
$step_data['maybe_mint_automation'] = $trigger ? 'yes' : 'no';
return $step_data;
}
/**
* Create a MainMint contact if conditions are met.
*
* This function checks if certain conditions are met and if the required classes
* exist. If the conditions are satisfied, it creates a new contact in the MainMint
* system with the provided email address and automation ID. This process may involve
* sending a double-opt-in email if configured.
*
* @since 1.9.6
*
* @param int $automation_id The ID of the automation.
* @param string $email The email address of the contact to be created.
*
* @return void
*/
public function maybe_create_mainmint_contact( $automation_id, $email ) {
if ( $automation_id && $email &&
class_exists( 'Mint\\MRM\\DataBase\\Tables\\AutomationMetaSchema' ) &&
class_exists( 'MintMail\\App\\Internal\\Automation\\AutomationModel' ) &&
class_exists( 'Mint\\MRM\\DataBase\\Tables\\AutomationSchema' )
) {
$is_exist = $this->maybe_automation_exist( $automation_id );
if ( $is_exist ) {
if ( !HelperFunctions::maybe_user( $email ) ) {
$is_double_optin = MRMCommon::is_double_optin_enable();
$parms = array(
'status' => $is_double_optin ? 'pending' : 'subscribed',
);
$contact = new ContactData( $email, $parms );
$contact_id = ContactModel::insert( $contact );
if ( $contact_id && $is_double_optin ) {
MessageController::get_instance()->send_double_opt_in( $contact_id );
}
}
}
}
}
/**
* Check if a specific automation exists.
*
* This private function checks whether a given automation ID exists in the MainMint
* system by querying the appropriate tables. It uses the provided automation ID to
* look for matching automations based on predefined conditions.
*
* @since 1.6.0
*
* @param int $automation_id The ID of the automation to check.
*
* @return bool True if the automation exists, false otherwise.
*/
private function maybe_automation_exist( $automation_id ) {
if ( ! $automation_id ) {
return false;
}
global $wpdb;
$automation_table = $wpdb->prefix . 'mint_automations';
$automation_meta_table = $wpdb->prefix . 'mint_automation_meta';
// Query to retrieve matching automations.
$automations = $wpdb->get_results(
$wpdb->prepare(
"SELECT automation.id as id
FROM $automation_table as automation
INNER JOIN $automation_meta_table as automation_meta
ON automation.id = automation_meta.automation_id
WHERE automation_meta.automation_id = %d
AND automation_meta.meta_key = %s
AND automation_meta.meta_value = %s",
array( $automation_id, 'source', 'wpf' )
),
ARRAY_A
);
if ( ! is_array( $automations ) || ! count( $automations ) ) {
return false;
}
return true;
}
/**
* Save automation after step duplicate
*
* @param int $funnel_id
* @param int $step_id
*
* @since 2.1.2
*/
public function save_automation_after_step_duplicate( $funnel_id, $step_id ){
if( $funnel_id && $step_id ){
$mint_automation = new Automation();
$automation_data = $mint_automation->prepare_automation_duplicate_data( $funnel_id, $step_id );
if( $automation_data ){
$mint_automation->save_or_update_automation( $automation_data, $funnel_id, $step_id );
}
}
}
} admin/modules/steps/checkout/asset/js/main.js 0000644 00000047623 14760024572 0015307 0 ustar 00 (function($) {
'use strict';
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
jQuery(document).ready(function() {
/**
* edit-field settings tab
*
* @since 1.0.0
*/
$('.edit-field-settings__single-tab-content:first-child').show();
$('.edit-field-settings__tab-nav a').on('click', function(e) {
e.preventDefault();
var dataID = $(this).attr('href');
$(this).parent('li').addClass('active').siblings().removeClass('active');
$(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).show();
$(this).parents('.checkout-edit-field-tab__content-wrapper').find(dataID).siblings().hide();
});
/**
* add new checkout field drawer
*
* @since 1.0.0
*/
$('.add-new-checkout-field-btn').on('click', function(e) {
e.preventDefault();
$(this).parents('.checkout-edit-field-tab__content-wrapper').find('.add-checkout-field-wrapper').addClass('show-drawer');
});
$('.add-checkout-field-close').on('click', function(e) {
e.preventDefault();
$(this).parents('.add-checkout-field-wrapper').removeClass('show-drawer');
});
/**
* edit checkout field drawer
*
* @since 1.0.0
*/
// $('button.edit-field').on('click', function(e) {
$(document).on("click", "button.edit-field", function(e) {
e.preventDefault();
$(this).parents('.checkout-edit-field-tab__content-wrapper').find('.edit-checkout-field-wrapper').addClass('show-drawer');
});
$('.add-checkout-field-close').on('click', function(e) {
e.preventDefault();
$(this).parents('.edit-checkout-field-wrapper').removeClass('show-drawer');
});
/**
* show edit field type options
*
* @since 1.0.0
*/
$('.wpfnl-edit-field-type').on('change', function(e) {
e.preventDefault();
var thisVal = $(this).val();
if( thisVal == 'select' ){
$(this).parents('.field-body').find('.field-type-options').show();
} else {
$(this).parents('.field-body').find('.field-type-options').hide();
}
});
});
jQuery(document).ready(function() {
var selectedType = $('.wpfnl-edit-field-type').val();
if( selectedType == 'select' ){
$('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').show();
} else {
$('.wpfnl-edit-field-type').parents('.field-body').find('.field-type-options').hide();
}
});
jQuery(document).ready(function() {
$('.wpfnl_muliple_select').select2();
/**
* get and show billing fields
* @since 1.0.1
*/
var stepId = window.CheckoutEditor.stepId;
var billingFields = window.CheckoutEditor.billingFields;
var shippingFields = window.CheckoutEditor.shippingFields;
var additionalFields = window.CheckoutEditor.additionalFields;
var unique_id ='';
// show_additional_field();
/**
* add option field as you need when add checkout field
* @since 1.0.0
*/
var i = 2;
$('.wpfnl_add_option').click(function(e) {
e.preventDefault();
i++;
$('.dynamic_option').append('');
});
/**
* remove option field as you need
*/
$(document).on('click', '.wpfnl_btn_remove', function(e) {
e.preventDefault();
var button_id = $(this).attr("id");
$("#row" + button_id + "").remove();
});
/**
* add checkout field
* @since 1.0.0
*/
$('.custom_checkout_add_field').click(function() {
var id = $(this).data('id');
if (id == 'additional') {
$("#wpfnl_name").val("additional_")
$(".wpfnl_id").val("additional_")
$("#hidden_field_add").val(id)
}
if (id == 'billing') {
$("#wpfnl_name").val("billing_")
$(".wpfnl_id").val("billing_")
$("#hidden_field_add").val(id)
}
if (id == 'shipping') {
$("#wpfnl_name").val("shipping_")
$(".wpfnl_id").val("shipping_")
$("#hidden_field_add").val(id)
}
});
/**
* edit checkout field
* @since 1.0.0
*/
// $(document).on("click", ".wpfnl_edit_row", function() {
// var id = $(this).data('id');
// var type = $(this).data('type');
// var parent_id = $(this).parent();
// unique_id = $(parent_id).parent().attr("id");
// var payload = {
// type: type,
// data: id,
// billing_fields: billingFields,
// shipping_fields: shippingFields,
// additional_fields: additionalFields,
// };
// wpAjaxHelperRequest("wpfnl-edit-row", payload)
// .success(function(data) {
// var jsonData = JSON.parse(data);
// var index;
// if (jsonData.index != 'custom') {
// $(".wpfnl_edit_type").prop("disabled", true);
// $("#wpfnl_edit_name").prop("disabled", true);
// $(".wpfnl_add_edit_option").hide();
// index = 'default';
// } else {
// $(".wpfnl_edit_type").prop("disabled", false);
// $(".wpfnl_edit_name").prop("disabled", false);
// index = 'custom';
// }
// $('.wpfnl_edit_type').val(jsonData.data.type);
// $('#wpfnl_edit_name').val(id);
// $('#wpfnl_hidden_array_index').val(id);
// $('#wpfnl_edit_label').val(jsonData.data.label);
// $('#wpfnl_edit_placeholder').val(jsonData.data.placeholder);
// $('#wpfnl_edit_default').val(jsonData.data.default);
// $('#wpfnl_edit_id').val(jsonData.data.id);
// $('#wpfnl_hidden_value').val(index);
// $('#wpfnl_hidden_index').val(id);
// $('#wpfnl_hidden_type').val(type);
// if(jsonData.data.validate){
// var validate_arr = jsonData.data.validate;
// for(var i=0 ;i 0 && option_value[0] != '') {
// $('.edit_field_option').remove();
// for (var i = 0; i < option_text.length; i++) {
// var field = ''
// $('.dynamic_option_edit').append(field);
// }
// }
// }
// })
// .error(function(response) {
// });
// })
/**
* Checkout Edit Field delete alert
*
* @since 1.0.0
*/
// $(document).on("click", ".delete-checkout-field", function() {
// $('.wpfnl-delete-alert-wrapper').css('display', 'flex');
// var index = $(this).data('id');
// var type = $(this).data('type');
// var parent_id = $(this).parent();
// var parents_id = $(parent_id).parent();
// var payload = {
// data: index,
// type: type,
// billing_fields:billingFields,
// shipping_fields:shippingFields,
// additional_fields:additionalFields,
// step_id:stepId
// };
// $(document).on("click", ".wpfnl-delete-confirm-btn .yes", function() {
// wpAjaxHelperRequest("wpfnl-delete-row", payload)
// .success(function(data) {
// $('.wpfnl-delete-alert-wrapper').hide();
// $(parents_id).remove();
// })
// });
// });
$(document).on("click", ".wpfnl-delete-confirm-btn .cancel", function() {
$('.wpfnl-delete-alert-wrapper').hide();
});
/**
* Restore to deafult checkout field for each section
* @since 1.0.0
*/
// $('.wpfnl_restore_btn').click(function() {
// var payload = {
// data: $(this).data('id'),
// billing_fields:billingFields,
// shipping_fields:shippingFields,
// additional_fields:additionalFields,
// step_id:stepId
// };
// var thisAlert = $(this).parents('.restore-btn').find('.wpfnl-alert');
// var thisLoader = $(this).parents('.restore-btn').find('.wpfnl-loader');
// thisLoader.css('display', 'inline-block');
// wpAjaxHelperRequest("wpfnl-restore-default", payload)
// .success(function(data) {
// thisAlert.text('Successfully Restored').addClass('wpfnl-success').fadeIn();
// thisLoader.hide();
// if('billing_success' == data){
// show_billing_field();
// setTimeout(function() {
// thisAlert.fadeOut().text('').removeClass('wpfnl-success');
// }, 2000);
// }
// if('shipping_success' == data){
// show_shipping_field();
// setTimeout(function() {
// thisAlert.fadeOut().text('').removeClass('wpfnl-success');
// }, 2000);
// }
// if('additional_success' == data){
// show_additional_field();
// setTimeout(function() {
// thisAlert.fadeOut().text('').removeClass('wpfnl-success');
// }, 2000);
// }
// })
// });
/**
* wpfnl_change_required
* change required option of each checkout field
* @since 1.0.0
*/
$(document).on("click", ".wpfnl_change_required", function() {
var id = $(this).data('id');
var type = $(this).data('type');
var payload = {
id:id,
type:type,
billing_fields:billingFields,
shipping_fields:shippingFields,
additional_fields:window.CheckoutEditor.additionalFields,
step_id:stepId
}
wpAjaxHelperRequest("wpfnl-change-required-edit-field", payload)
.success(function() {
})
})
/**
* wpfnl_change_enable
* change enable option of each checkout field
* @since 1.0.0
*/
/**
* wpfnl_submit
* Add field for each section
* @since 1.0.0
*/
// $(document).on("click", ".wpfnl_submit", function(e) {
// e.preventDefault();
// e.stopPropagation();
// var thisAlert = $(this).parents('.field-footer').find('.wpfnl-alert');
// var thisLoader = $(this).parents('.field-footer').find('.wpfnl-loader');
// thisLoader.css('display', 'inline-block');
// var fields = $('.add_field_form').serialize();
// var payload =
// {
// fields: fields,
// billing_fields: billingFields,
// shipping_fields: shippingFields,
// additional_fields: additionalFields,
// step_id:stepId
// }
// wpAjaxHelperRequest("wpfnl-add-field", payload)
// .success(function(data) {
// $('.wpfnl_name').val('');
// $('.wpfnl_label').val('');
// $('.wpfnl_placeholder').val('');
// $('.wpfnl_default').val('');
// $('.wpfnl_validation').val('');
// $('.wpfnl_required').val('');
// $('.wpfnl_enable').val('');
// $('.wpfnl_show').val('');
// $('.wpfnl_edit_type_option').val('');
// thisAlert.text('Successfully Saved').addClass('wpfnl-success').fadeIn();
// thisLoader.hide();
// if('success' == data){
// show_additional_field();
// show_billing_field();
// show_shipping_field();
// }
// setTimeout(function() {
// thisAlert.fadeOut().text('').removeClass('wpfnl-success');
// }, 2000);
// })
// })
/**
* wpfnl_edit_submit
* Edit field for each section
* @since 1.0.0
*/
$(document).on("click", ".wpfnl_edit_submit", function(e) {
e.preventDefault();
e.stopPropagation();
$('.wpfnl-loader').css('display','inline-block');
var fields = $('.edit_field_form').serialize();
var payload = {
fields:fields,
billing_fields: billingFields,
shipping_fields: shippingFields,
additional_fields: additionalFields,
step_id:stepId
}
wpAjaxHelperRequest("wpfnl-edit-field", payload)
.success(function(data) {
$('#'+unique_id).children('.field-label').text($('#wpfnl_edit_label').val())
$('#'+unique_id).children('.field-type').text($('.wpfnl_edit_type').val())
$('#'+unique_id).children('.field-name').text($('#wpfnl_edit_name').val())
$('#'+unique_id).children('.field-placeholder').text($('#wpfnl_edit_placeholder').val())
if($(".wpfnl_edit_required").prop("checked") == true){
$('#'+unique_id).children('.field-required').children('.wpfnl-switcher').children('.wpfnl_change_required').prop("checked",true)
}else{
$('#'+unique_id).children('.field-required').children('.wpfnl-switcher').children('.wpfnl_change_required').prop("checked",false)
}
if($(".wpfnl_edit_enable").prop("checked") == true){
$('#'+unique_id).children('.field-required').children('.wpfnl-switcher').children('.wpfnl_change_enable').prop("checked",true)
}else{
$('#'+unique_id).children('.field-required').children('.wpfnl-switcher').children('.wpfnl_change_enable').prop("checked",false)
}
var validations = [];
$('.edit_validation_select').each(function() {
validations.push($(this).val());
});
$('#'+unique_id).children('.field-validation').text(validations.toString());
$('.wpfnl-alert').text('Successfully Updated').addClass('wpfnl-success').fadeIn();
$('.wpfnl-loader').css('display','none');
setTimeout(function() {
$('.wpfnl-alert').fadeOut().text('').removeClass('wpfnl-success');
}, 2000);
})
})
})
})(jQuery);
admin/modules/steps/checkout/checkout-fields/views/partials/add-checkout-field-drawer.php 0000644 00000016554 14760024572 0025725 0 ustar 00