コード例 #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');
                 }
             }
         }
     }
 }
コード例 #2
0
 function smart_offers_generate_embed_offer()
 {
     global $sa_smart_offers;
     check_ajax_referer('so_generate_embed_offer', 'security');
     if (empty($_POST['post_id']) || $_POST['action'] != 'generate_embed_offer') {
         return;
     }
     $so_offer = new SO_Offer();
     $data = array();
     $offer_id = $_POST['post_id'];
     $where_url = get_option('siteurl');
     $offer_content = $so_offer->return_post_content($offer_id, $page = '', $where_url);
     $data['content'] = apply_filters('the_content', $offer_content);
     $button_style = get_option('so_accept_button_styles');
     if ($button_style == 'smart_offers_custom_style_button') {
         $accept_css = get_option('so_css_for_accept');
         $style_for_accept_text = "";
     } else {
         $accept_css = get_option($button_style);
         $style_for_accept_text = "div.so_accept a { text-decoration: none !important; color: white; }";
     }
     $skip_css = get_option('so_css_for_skip');
     $style_for_accept = "div.so_accept { {$accept_css} }";
     $style_for_skip = "div.so_skip { {$skip_css} }";
     $data['style'] = $style_for_accept . $style_for_skip . $style_for_accept_text;
     echo json_encode($data);
     die;
 }