| |
| <?php
|
|
|
|
|
|
|
|
|
| if ( class_exists( 'WOO_Product_Expiry') ){
|
|
|
|
|
|
|
|
|
| function wcv_pefwc_add_fields( $post_id ){
|
|
|
|
|
| $expiry_date = get_post_meta( $post_id, 'woo_expiry_date', true );
|
| WCVendors_Pro_Form_Helper::input(
|
| array(
|
| 'post_id' => $post_id,
|
| 'id' => 'woo_expiry_date',
|
| 'class' => 'wcv-datepicker wcv-init-picker',
|
| 'label' => __( 'Expiry Date', 'wcvendors-pro' ),
|
| 'value' => $expiry_date,
|
| 'custom_attributes' => array(
|
| 'data-start-date' => '',
|
| 'data-close-text' => __( 'Close', 'wcvendors-pro' ),
|
| 'data-clean-text' => __( 'Clear', 'wcvendors-pro' ),
|
| 'data-of-text' => __( ' of ', 'wcvendors-pro' ),
|
| ),
|
| )
|
| );
|
|
|
| $expiry_action = get_post_meta( $post_id, 'woo_expiry_action', true );
|
| WCVendors_Pro_Form_Helper::select(
|
| array(
|
| 'id' => 'woo_expiry_action',
|
| 'label' => __( 'Action', 'product-expiry-for-woocommerce' ),
|
| 'options' => array(
|
| '' => __( 'Nothing', 'product-expiry-for-woocommerce' ),
|
| 'draft' => __( 'Make it Draft', 'product-expiry-for-woocommerce' ),
|
| ),
|
| 'desc_tip' => __( 'What to do when this product expires?', 'product-expiry-for-woocommerce' ),
|
| 'description' => __( 'What to do when this product expires?', 'product-expiry-for-woocommerce' )
|
| )
|
| );
|
| }
|
| add_action( 'wcvendors_product_options_general_product_data_after', 'wcv_pefwc_add_fields' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function wcv_pefwc_save_fields( $post_id ){
|
|
|
| $product = wc_get_product( $post_id );
|
|
|
|
|
| $woo_expiry_date = isset( $_POST['woo_expiry_date'] ) ? sanitize_text_field( $_POST[ 'woo_expiry_date' ] ) : '';
|
| $woo_expiry_action = isset( $_POST['woo_expiry_action'] ) ? sanitize_text_field( $_POST[ 'woo_expiry_action' ] ) : '';
|
|
|
| $product->update_meta_data( 'woo_expiry_date', sanitize_text_field( $woo_expiry_date ) );
|
| $product->update_meta_data( 'woo_expiry_action', sanitize_text_field( $woo_expiry_action ) );
|
|
|
| if ($woo_expiry_date != '' && $woo_expiry_action != '') {
|
| wp_clear_scheduled_hook( 'woo_expiry_schedule_action', array($post_id) );
|
| wp_schedule_single_event( strtotime($woo_expiry_date), 'woo_expiry_schedule_action', array($post_id) );
|
| }
|
|
|
| $product->save();
|
|
|
| }
|
| add_action ('wcv_save_product','wcv_pefwc_save_fields');
|
|
|
|
|
|
|
|
|
| function wcv_pefwc_show_date( $row_status, $status, $product_type, $date, $stock_status, $product ){
|
|
|
| $expiry_date = get_post_meta( $product->get_id(), 'woo_expiry_date', true );
|
|
|
| if ( !empty( $expiry_date ) ){
|
| $row_status = sprintf(
|
| '<span class="status %s">%s</span><br />
|
| <span class="product_type %s">%s</span><br />
|
| <span class="product_date">%s</span><br />
|
| <span class="product_expiry"><strong>'.__( 'Expires: ', 'wcvendors-pro' ) .'%s</strong></span><br />
|
| <span class="stock_status">%s</span>',
|
| $status,
|
| $status,
|
| $product_type,
|
| $product_type,
|
| $date,
|
| date_i18n( get_option( 'date_format' ), strtotime( $expiry_date ) ),
|
| $stock_status
|
| );
|
| }
|
| return $row_status;
|
| }
|
| add_filter( 'wcv_product_row_status', 'wcv_pefwc_show_date', 10, 6 );
|
|
|
| }
|
|
|
| |
| |