Support » Plugin: Woocommerce Product Availability Scheduler » Compatibility with WCMp WC-Marketplace

  • Hello,

    Good plugin, does what it claims elegantly. I just wanted to share code that allows this plugin to integrate with WCMp WC-Marketplace

    /* WC Marketplace Integration with Product Scheduler*/
    /**
    * Add Custom Tab in add product page.
    * @author WC Marketplace, NKNov12
    * @version 3.3.0
    */
    add_filter( “wcmp_product_data_tabs”, “wpas_schedule_sale_data_tab_wcmp” );
    function wpas_schedule_sale_data_tab_wcmp( $product_data_tabs )
    {
    $product_data_tabs[“wpas-schedule-sale-tab”] = array(
    “label” => __( “Availability Scheduler”, “dc-woocommerce-multi-vendor” ),
    “target” => “wpas_product_data_wcmp”,
    “class” => array( ), );
    return $product_data_tabs;
    }

    /**
    * Add Custom Tab content in add product page.
    * @author WC Marketplace, NKNov12
    * @version 3.3.0
    */
    function add_custom_product_data_content( $pro_class_obj, $product, $post ) {
    $now=time();
    $product_id=$product->get_id();

    $status=get_post_meta($product_id,’wpas_schedule_sale_status’,true);
    $start_time=get_post_meta($product_id,’wpas_schedule_sale_st_time’,true);
    $end_time=get_post_meta($product_id,’wpas_schedule_sale_end_time’,true);
    $mode=get_post_meta($product_id,’wpas_schedule_sale_mode’,true);
    $countdown=get_post_meta($product_id,’wpas_schedule_sale_countdown’,true);
    if(!empty($start_time))
    {
    $start_date=date(‘Y-m-d’, $start_time);
    $st_mm=date(‘m’, $start_time);
    $st_dd=date(‘d’, $start_time);
    $st_hh=date(‘H’, $start_time);
    $st_mn=date(‘i’, $start_time);
    }
    if(isset($end_time) &!empty($end_time))
    {
    $end_date=date(‘Y-m-d’, $end_time);
    $end_mm=date(‘m’, $end_time);
    $end_dd=date(‘d’, $end_time);
    $end_hh=date(‘H’, $end_time);
    $end_mn=date(‘i’, $end_time);
    }
    //prnt_r($product->get_id());die;
    //$hh = get_post_meta($product->get_id() , ‘_custom_text_field’ );
    //print_r($hh);
    ?>
    <div role=”tabpanel” class=”tab-pane fade” id=”wpas_product_data_wcmp”> <!– just make sure tabpanel id should replace with your added tab target –>
    <div class=”row-padding”>
    <div class=”form-group”>
    <label class=”control-label col-sm-3 col-md-3″ for=’wpas_select_status’><?php _e( ‘Status’, ‘dc-woocommerce-multi-vendor’ ); ?></label>
    <div class=”col-md-6 col-sm-9″>
    <select name=’wpas_select_status’ class=”form-control” id=”wpas_select_status_wcmp”>
    <option <?php if($status==0){ echo “selected”; } ?> value=’0′>Disable</option>
    <option <?php if($status==1){ echo “selected”; } ?> value=’1′>Enable</option>
    </select>
    </div>
    </div>
    <div class=”form-group”>
    <label class=”control-label col-sm-3 col-md-3″ for=’_select_start_time’><?php _e( ‘Start Time’, ‘dc-woocommerce-multi-vendor’ ); ?></label>
    <div class=”col-md-6 col-sm-9″>
    <input type=”text” id=”wpas_st_date_wcmp” class=”form-control inline-input” name=”wpas_st_date” value=”<?php echo $start_date; ?>” placeholder=”From… YYYY-MM-DD” maxlength=”10″ autocomplete=”off”>
    <span class=”inline-input”> @</span>
    <span class=”screen-reader-text”>Hour</span>
    <input type=”text” id=”wpas_st_hh_wcmp” class=”form-control inline-input” name=”wpas_st_hh” placeholder=”HH” value=”<?php echo $st_hh; ?>” size=”2″ maxlength=”2″ autocomplete=”off”><span class=”inline-input”>:</span>
    <span class=”screen-reader-text”>Minute</span>
    <input type=”text” id=”wpas_st_mn_wcmp” class=”form-control inline-input” name=”wpas_st_mn” placeholder=”MM” value=”<?php echo $st_mn; ?>” size=”2″ maxlength=”2″ autocomplete=”off”>
    <span class=”inline-input”>GMT</span>
    </div>
    </div>
    <div class=”form-group”>
    <label class=”control-label col-sm-3 col-md-3″ for=’_select_end_time’><?php _e( ‘End Time’, ‘dc-woocommerce-multi-vendor’ ); ?></label>
    <div class=”col-md-6 col-sm-9″>
    <input type=”text” id=”wpas_end_date_wcmp” class=”form-control inline-input” name=”wpas_end_date” value=”<?php echo $end_date; ?>” placeholder=”From… YYYY-MM-DD” maxlength=”10″ autocomplete=”off”>
    <span class=”inline-input”> @</span>
    <span class=”screen-reader-text”>Hour</span>
    <input type=”text” id=”wpas_end_hh_wcmp” class=”form-control inline-input” name=”wpas_end_hh” placeholder=”HH” value=”<?php echo $end_hh; ?>” size=”2″ maxlength=”2″ autocomplete=”off”><span class=”inline-input”>:</span>
    <span class=”screen-reader-text”>Minute</span>
    <input type=”text” id=”wpas_end_mn_wcmp” class=”form-control inline-input” name=”wpas_end_mn” placeholder=”MM” value=”<?php echo $st_mn; ?>” size=”2″ maxlength=”2″ autocomplete=”off”>
    <span>GMT</span>
    </div>
    </div>
    <div class=”form-group”>
    <label class=”control-label col-sm-3 col-md-3″ for=’_select_end_time’><?php _e( ‘CountDown’, ‘dc-woocommerce-multi-vendor’ ); ?></label>
    <div class=”col-md-6 col-sm-9″>
    <select name=’countdown’ class=”form-control” id=”countdown_wcmp”>
    <option <?php if($countdown==0){ echo “selected”; } ?> value=’0′>Disable</option>
    <option <?php if($countdown==1){ echo “selected”; } ?> value=’1′>Enable</option>
    </select>
    </div>
    </div>
    <div class=”form-group”>
    <p class=”form-field wpas_note control-label col-md-9 col-sm-12″>Note: Start time and End time will be on GMT, Current GMT time is: <?php echo date(“Y-m-d @ H:i”,$now); ?></p>
    </div>
    </div>
    </div>
    <?php
    }
    add_action( ‘wcmp_product_tabs_content’, ‘add_custom_product_data_content’, 10, 3 );

    /**
    * Save Custom Tab content data.
    * @author WC Marketplace, NKNov12
    * @version 3.3.0
    */
    function wpas_schedule_sale_save_data_tab_wcmp( $product, $post_data ) {
    $wpas_error=false;
    $wpas_st_hh=00;
    $wpas_st_mn=00;
    $wpas_end_hh=00;
    $wpas_end_mn=00;
    $wpas_status =sanitize_text_field($post_data[‘wpas_select_status’]);
    $countdown =sanitize_text_field($post_data[‘countdown’]);
    $wpas_st_date=sanitize_text_field($post_data[‘wpas_st_date’]);
    if(!empty($post_data[‘wpas_st_hh’])) $wpas_st_hh=sanitize_text_field($post_data[‘wpas_st_hh’]);
    if(!empty($post_data[‘wpas_st_mn’])) $wpas_st_mn=sanitize_text_field($post_data[‘wpas_st_mn’]);
    $wpas_end_date=sanitize_text_field($post_data[‘wpas_end_date’]);
    if(!empty($post_data[‘wpas_end_hh’])) $wpas_end_hh=sanitize_text_field($post_data[‘wpas_end_hh’]);
    if(!empty($post_data[‘wpas_end_mn’])) $wpas_end_mn=sanitize_text_field($post_data[‘wpas_end_mn’]);
    $wpas_start_schedule_hook=”wpas_start_shedule_sale”;
    $wpas_end_schedule_hook=”wpas_end_shedule_sale”;
    //Y-m-d H:i:s
    $wpas_st_time=strtotime($wpas_st_date.” “.$wpas_st_hh.”:”.$wpas_st_mn.”:00″);
    //echo “start time”.$wpas_st_time;
    $wpas_end_time=strtotime($wpas_end_date.” “.$wpas_end_hh.”:”.$wpas_end_mn.”:00″);
    if($wpas_status==1)
    { wp_clear_scheduled_hook( $wpas_start_schedule_hook, array($post->ID));
    wp_clear_scheduled_hook( $wpas_end_schedule_hook, array($post->ID) );
    wp_schedule_single_event($wpas_st_time, $wpas_start_schedule_hook,array($post->ID));
    wp_schedule_single_event($wpas_end_time, $wpas_end_schedule_hook,array($post->ID));
    }
    // Save Data

    if (!empty($wpas_st_date) && !empty($wpas_end_date)) {

    update_post_meta(absint( $post_data[‘post_ID’] ),’wpas_schedule_sale_status’,$wpas_status);
    update_post_meta(absint( $post_data[‘post_ID’] ),’wpas_schedule_sale_st_time’,$wpas_st_time);
    update_post_meta(absint( $post_data[‘post_ID’] ),’wpas_schedule_sale_end_time’,$wpas_end_time);
    update_post_meta(absint( $post_data[‘post_ID’] ),’wpas_schedule_sale_countdown’,$countdown);

    if($wpas_st_time > time())
    {
    update_post_meta(absint( $post_data[‘post_ID’] ),’wpas_schedule_sale_mode’,0);
    }
    }
    }
    add_action( ‘wcmp_process_product_object’, ‘wpas_schedule_sale_save_data_tab_wcmp’, 10, 2 );

  • The topic ‘Compatibility with WCMp WC-Marketplace’ is closed to new replies.