Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* enqueue scripts */
- function cp_enqueue_scripts() {
- wp_enqueue_script( 'cp_modal_js', get_stylesheet_directory_uri() . '/js/modal.js', array( 'jquery' ));
- wp_enqueue_script( 'cp_loc_file', get_stylesheet_directory_uri() . '/js/var.js');
- wp_localize_script('cp_loc_file', 'cp_loc_ajaxpath', admin_url('admin-ajax.php'));
- }
- add_action('wp_enqueue_scripts', 'cp_enqueue_scripts');
- /* quick view modal */
- add_action("wp_ajax_nopriv_cp_get_product_details", "cp_get_product_details");
- add_action("wp_ajax_cp_get_product_details", "cp_get_product_details");
- function cp_get_product_details() {
- $product_id = isset( $_POST['cp_productId']) ? $_POST['cp_productId'] : false;
- if ( isset( $_POST['cp_productId']) ) {
- // get product details
- $product = wc_get_product( $product_id );
- $html = '<div class="cp_modal_image"><img src="' . wp_get_attachment_image_src( $product->image_id, 'large' )[0] . '"></div>';
- $html .= '<div class="cp_modal_details">';
- $html .= '<div class="cp_modal_content_scroller">';
- $html .= '<div class="cp_modal_heading"><h2>' . $product->name . '</h2></div>';
- $html .= '<div class="cp_modal_excerpt">' . $product->post->post_excerpt . '</div>';
- $html .= '<div class="cp_modal_description">' . wpautop( $product->post->post_content ) . '</div>';
- $html .= '</div>'; // end scroller
- $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>';
- $html .= '</div>';
- echo json_encode( $html );
- }
- wp_die();
- }
- /* load modal */
- function cp_inject_modal() {
- ?>
- <div class="cp_modal_loader">
- <div class="lds-ripple"><div></div><div></div></div>
- </div>
- <div class="cp_modal_wrapper">
- <div class="cp_modal_content">
- <!-- inject content -->
- </div>
- </div>
- <?php
- }
- add_action('wp_footer', 'cp_inject_modal', -1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement