Exemplo n.º 1
0
 /**
  * Function to show offer just after Place Order button is clicked on checkout page, if a valid offer is available
  */
 function smart_offers_post_checkout()
 {
     global $sa_smart_offers;
     $so_offer = new SO_Offer();
     $so_offers = new SO_Offers();
     $page = 'post_checkout_page';
     list($where, $where_url) = $so_offers->get_page_details();
     $so_get_offers = $so_offers->get_offers($offer_ids = null);
     $so_offers_id = $so_offers->get_valid_offer_ids($so_get_offers);
     //$offer_id = $so_get_offers['offer_data'][0]['post_id'];
     if (!empty($so_offers_id)) {
         foreach ($so_offers_id as $key => $value) {
             $offer_id = $key;
             $offer_rule_page_options = get_post_meta($offer_id, 'offer_rule_page_options', true);
             $offer_rule_pages = explode(',', $offer_rule_page_options);
             if (!in_array($page, $offer_rule_pages)) {
                 continue;
             } else {
                 $show_offer_as = get_post_meta($offer_id, 'so_show_offer_as', true);
                 if ($show_offer_as == "offer_as_popup") {
                     if (!wp_script_is('jquery')) {
                         wp_enqueue_script('jquery');
                         wp_enqueue_style('jquery');
                     }
                     if (!wp_script_is('so_magnific_popup_js')) {
                         wp_enqueue_script('so_magnific_popup_js', trailingslashit(plugins_url()) . dirname(plugin_basename(SO_PLUGIN_FILE)) . '/assets/js/jquery.magnific-popup.js');
                     }
                     if (!wp_style_is('so_magnific_popup_css')) {
                         wp_enqueue_style('so_magnific_popup_css', trailingslashit(plugins_url()) . dirname(plugin_basename(SO_PLUGIN_FILE)) . '/assets/css/magnific-popup.css');
                         wp_enqueue_style('so_frontend_css');
                     }
                 }
                 ?>
                 <div class="smart-offers-post-action" id="smart-offers-post-action">
                     <?php 
                 $sa_so_offer_content = $so_offer->return_post_content($offer_id, $page, $where_url);
                 $processed_offer_content = apply_filters('the_content', $sa_so_offer_content);
                 echo $processed_offer_content;
                 ?>
                 </div>
                 <?php 
                 $js = "jQuery(document).ready(function() {\n                                        var post_element = jQuery( 'div#smart-offers-post-action' );\n                                        if( ( post_element.length ) > 0 ) {\n                                            if( ( post_element.find( 'div.so-offer-content' ).length ) > 0 ){\n                                                post_element.find( 'div.so-offer-content' ).hide();\n                                            }\n                                        }\n                                    });\n\n                                jQuery('body').on( 'click', 'input#place_order.button.alt', function( e ) {\n                                    var post_element = jQuery( 'div#smart-offers-post-action' );\n                                    if( ( post_element.length ) > 0 ) {\n                                        e.preventDefault();\n                                        var checkout_form_data = jQuery('form.checkout').serialize();\n                                        jQuery.ajax({\n                                            url: '" . admin_url('admin-ajax.php') . "',\n                                            type: 'POST',\n                                            dataType: 'json',\n                                            data: {\n                                                action: 'parse_checkout_form_data',\n                                                security: '" . wp_create_nonce('post_checkout_offers') . "',\n                                                form_data: checkout_form_data\n                                            },\n                                            success: function( response ) {\n                                                post_element.show();\n                                                if ( response.success != '' && response.success != undefined && response.success == 'no' ) {\n                                                    console.log( '" . __('Unable to save checkout form data.', SA_Smart_Offers::$text_domain) . "' );\n                                                }\n                                            }\n                                        });\n                                        if( ( post_element.find( 'div.so-offer-content.so-inline' ).length ) > 0 ) {\n                                            jQuery( 'form.checkout' ).hide();\n                                            post_element.find( 'div.so-offer-content' ).show();\n                                        } else if( ( post_element.find( 'div.so-offer-content.so-popup' ).length ) > 0 ) {\n                                            post_element.find( 'div.so-offer-content' ).addClass( 'white-popup' );\n                                            jQuery.magnificPopup.open({\n                                                items: {\n                                                          src: jQuery( 'div#smart-offers-post-action div.so-offer-content' )\n                                                        },\n                                                type: 'inline',\n                                                modal: true,\n                                                tError: '" . __("The content could not be loaded.", SA_Smart_Offers::$text_domain) . "'\n                                            });\n                                            post_element.find( 'div.so-offer-content.so-popup' ).show();\n                                        }\n                                    }\n                                });\n                            ";
                 $sa_smart_offers->enqueue_js($js);
                 // After accepting an offer, 'offer_shown' was counted additionally, hence skipping it
                 if (!(!empty($_REQUEST['so_action']) && $_REQUEST['so_action'] == 'accept')) {
                     $so_offer->update_accept_skip_count($offer_id, 'offer_shown');
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Shortcode to show offer
  */
 function shortcode_for_showing_offers($atts)
 {
     extract(shortcode_atts(array('display_as' => '', 'offer_ids' => ''), $atts));
     $so_offers = new SO_Offers();
     $offers_data = $so_offers->get_offers($offer_ids);
     if (empty($offers_data)) {
         return;
     }
     $so_offer = new SO_Offer();
     $so_offer->prepare_offer($display_as, $offers_data);
 }