Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Monday, May 11, 2020

Send inquiry button code using contact form and popup maker in wordpress

add this code in your theme functions.php


//Custom Code
//send inquiry contactform tab on product detail page
//add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' );
function product_enquiry_tab( $tabs ) {
    $tabs['test_tab'] = array(
        'title'     => __( 'Send Inquiry', 'woocommerce' ),
        'priority'  => 50,
        'callback'  => 'product_enquiry_tab_form'
    );
    return $tabs;
}
function product_enquiry_tab_form() {
    global $product;
    //If you want to have product ID also
    //$product_id = $product->id;
    $subject    =   "Enquire about ".$product->post->post_title;
    echo "<h3>".$subject."</h3>";
    echo do_shortcode('[contact-form-7 id="3319" title="popup form"]'); //add your contact form shortcode here ..
    ?>
    <script>
    (function($){
        $(".product_name").val("<?php echo $subject; ?>");
    })(jQuery);
    </script> 
    <?php 
}

//send inquiry button on product page
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product  ) {
    $button_text = __("Send Inquiry", "woocommerce");
    $subject = $product->post->post_title;
    $button = '<a class="button product_send_inquiry_btn" data-title="'.$subject.'" href="' . $product->get_permalink() . '">' . $button_text . '</a>';

    return $button;
}

//send inquiry button on product detail page
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 36);
function my_extra_button_on_product_page() {
  global $product,$post;
  $button_text = __("Send Inquiry", "woocommerce");
    $subject = get_post_field('post_title', $post->ID);
    $button = '<a class="button product_send_inquiry_btn" data-title="'.$subject.'" >' . $button_text . '</a>';

    echo $button;
}

//get product name on button click script add in footer
add_action('wp_footer', 'add_send_btn_script');
function add_send_btn_script() {
    ?>
    <script>
    jQuery('.product_send_inquiry_btn').on('click', function (e) {
        e.preventDefault();
        var product_name = "Product Inquiry for "+jQuery(this).data('title');
        jQuery(".product_name").val(product_name);
    });
    </script>
    <?php
    return true;
}

Monday, July 23, 2018

wordpress - Woocommerce when deleting a product, also delete the product gallery and product image automatically

1. FOR Remove Attached Image with Product in Woocommerce 

add_action( 'before_delete_post', 'delete_product_images', 10, 1 );
function delete_product_images( $post_id )
{
    $product = wc_get_product( $post_id );
    if ( !$product ) {
        return;
    }
    $featured_image_id = $product->get_image_id();
    $image_galleries_id = $product->get_gallery_image_ids();
    if( !empty( $featured_image_id ) ) {
        wp_delete_post( $featured_image_id );
    }
    if( !empty( $image_galleries_id ) ) {
        foreach( $image_galleries_id as $single_image_id ) {
            wp_delete_post( $single_image_id );
        }
    }
}

2. FOR Remove Attached Image with Post And Page


add_action("before_delete_post","wdm_delete_post_images",10,1);
function wdm_delete_post_images($post_id)
{
 global $wpdb;
          $args = array(
                'post_parent' => $post_id,
                'post_type'   => 'attachment',
                'numberposts' => -1,
                'post_status' => 'any'
        );
        $childrens = get_children( $args);
        if($childrens):
            foreach($childrens as $attachment):
             wp_delete_attachment( $attachment->ID, true );
             $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = ".$attachment->ID);
             wp_delete_post($attachment->ID,true );
            endforeach;
        endif;
}
loading...

Product Category Demo in laravel

https://drive.google.com/file/d/1kuyeT3LA22IuN3o_kypOyXesEXMLv31e/view?usp=sharing