SHARE
TWEET

Untitled

a guest Apr 24th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /* enqueue scripts */
  3.  
  4. function cp_enqueue_scripts() {
  5.     wp_enqueue_script( 'cp_modal_js', get_stylesheet_directory_uri() . '/js/modal.js', array( 'jquery' ));
  6.     wp_enqueue_script( 'cp_loc_file', get_stylesheet_directory_uri() . '/js/var.js');
  7.     wp_localize_script('cp_loc_file', 'cp_loc_ajaxpath', admin_url('admin-ajax.php'));
  8. }
  9. add_action('wp_enqueue_scripts', 'cp_enqueue_scripts');
  10.  
  11. /* quick view modal */
  12.  
  13. add_action("wp_ajax_nopriv_cp_get_product_details", "cp_get_product_details");
  14. add_action("wp_ajax_cp_get_product_details", "cp_get_product_details");
  15.  
  16. function cp_get_product_details() {
  17.     $product_id = isset( $_POST['cp_productId']) ? $_POST['cp_productId'] : false;
  18.  
  19.     if ( isset( $_POST['cp_productId']) ) {
  20.        
  21.         // get product details
  22.         $product = wc_get_product( $product_id );
  23.        
  24.         $html = '<div class="cp_modal_image"><img src="' . wp_get_attachment_image_src( $product->image_id, 'large' )[0] . '"></div>';
  25.         $html .= '<div class="cp_modal_details">';        
  26.         $html .= '<div class="cp_modal_content_scroller">';        
  27.         $html .= '<div class="cp_modal_heading"><h2>' . $product->name . '</h2></div>';
  28.         $html .= '<div class="cp_modal_excerpt">' . $product->post->post_excerpt . '</div>';
  29.         $html .= '<div class="cp_modal_description">' . wpautop( $product->post->post_content ) . '</div>';        
  30.         $html .= '</div>'; // end scroller
  31.  
  32.         $html .= '<div class="cp_modal_contact_button"><span class="cp-notification-bottom">Some notification.</span><a href="' . get_permalink( $product_id ) . '" class="cp-default-button">Read more</a></div>';
  33.        
  34.         $html .= '</div>';
  35.        
  36.         echo json_encode( $html );
  37.     }
  38.    
  39.     wp_die();
  40. }
  41.  
  42. /* load modal */
  43.  
  44. function cp_inject_modal() {
  45.     ?>
  46.     <div class="cp_modal_loader">
  47.         <div class="lds-ripple"><div></div><div></div></div>
  48.     </div>
  49.     <div class="cp_modal_wrapper">
  50.         <div class="cp_modal_content">
  51.           <!-- inject content -->
  52.         </div>
  53.     </div>
  54.     <?php
  55. }
  56. add_action('wp_footer', 'cp_inject_modal', -1);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top