Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Save extra product data
- *
- * @since 2.5.3
- *
- * @param integer $post_id
- *
- * @return void
- */
- public function save_pro_product_data( $post_id ) {
- if ( ! $post_id ) {
- return;
- }
- $is_virtual = isset( $_POST['_virtual'] ) ? 'yes' : 'no';
- $product_type = empty( $_POST['product_type'] ) ? 'simple' : stripslashes( $_POST['product_type'] );
- // Save lot discount options
- // $is_lot_discount = isset( $_POST['_is_lot_discount'] ) ? $_POST['_is_lot_discount'] : 'no';
- $is_lot_discount = 'yes';
- if ( $is_lot_discount == 'yes' ) {
- $lot_discount_quantity = isset( $_POST['_lot_discount_quantity'] ) ? $_POST['_lot_discount_quantity'] : 0;
- $lot_discount_amount = isset( $_POST['_lot_discount_amount'] ) ? $_POST['_lot_discount_amount'] : 0;
- //edited code
- $lot_discount_quantity_two = isset( $_POST['_lot_discount_quantity_two'] ) ? $_POST['_lot_discount_quantity_two'] : 0;
- $lot_discount_amount_two = isset( $_POST['_lot_discount_amount_two'] ) ? $_POST['_lot_discount_amount_two'] : 0;
- $lot_discount_quantity_three = isset( $_POST['_lot_discount_quantity_three'] ) ? $_POST['_lot_discount_quantity_three'] : 0;
- $lot_discount_amount_three = isset( $_POST['_lot_discount_amount_three'] ) ? $_POST['_lot_discount_amount_three'] : 0;
- $discount_status = $_POST['_discount_status'];
- //edited code
- if ( $lot_discount_quantity == '0' || $lot_discount_amount == '0' ) {
- update_post_meta( $post_id, '_lot_discount_quantity', 0);
- update_post_meta( $post_id, '_lot_discount_amount', 0);
- update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
- update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
- update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
- update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
- update_post_meta( $post_id, '_is_lot_discount', 'yes' );
- } else {
- update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
- update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount);
- update_post_meta( $post_id, '_is_lot_discount', 'yes' );
- update_post_meta($post_id,'_discount_status',$discount_status);
- }
- //edited Code
- if ($lot_discount_quantity_two == '0' || $lot_discount_amount_two == '0') {
- update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
- update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
- update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
- update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
- } else if($lot_discount_quantity != '0'){
- if($lot_discount_quantity < $lot_discount_quantity_two){
- update_post_meta( $post_id, '_lot_discount_quantity_two', $lot_discount_quantity_two );
- update_post_meta( $post_id, '_lot_discount_amount_two', $lot_discount_amount_two );
- }
- }
- if ( $lot_discount_quantity_three == '0' || $lot_discount_amount_three == '0') {
- update_post_meta( $post_id, '_lot_discount_quantity_three', 0);
- update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
- } else if($lot_discount_quantity != '0') {
- if($lot_discount_quantity_two != '0'){
- if($lot_discount_quantity < $lot_discount_quantity_two && $lot_discount_quantity_two < $lot_discount_quantity_three){
- update_post_meta( $post_id, '_lot_discount_quantity_three', $lot_discount_quantity_three );
- update_post_meta( $post_id, '_lot_discount_amount_three', $lot_discount_amount_three );
- }
- }
- }
- } else if ( $is_lot_discount == 'no') {
- // update_post_meta( $post_id, '_lot_discount_quantity', 0 );
- // update_post_meta( $post_id, '_lot_discount_amount', 0 );
- // update_post_meta( $post_id, '_lot_discount_quantity_two', 0 );
- // update_post_meta( $post_id, '_lot_discount_amount_two', 0 );
- // update_post_meta( $post_id, '_lot_discount_quantity_three', 0 );
- // update_post_meta( $post_id, '_lot_discount_amount_three', 0 );
- // //update_post_meta( $post_id, '_is_lot_discount', 'no' );
- update_post_meta( $post_id, '_is_lot_discount', 'yes' );
- }
- // // Save lot discount options
- // $is_lot_discount = isset( $_POST['_is_lot_discount'] ) ? $_POST['_is_lot_discount'] : 'no';
- // if ( $is_lot_discount == 'yes' ) {
- // $lot_discount_quantity = isset( $_POST['_lot_discount_quantity'] ) ? $_POST['_lot_discount_quantity'] : 0;
- // $lot_discount_amount = isset( $_POST['_lot_discount_amount'] ) ? $_POST['_lot_discount_amount'] : 0;
- // if ( $lot_discount_quantity == '0' || $lot_discount_amount == '0' ) {
- // update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
- // update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount );
- // update_post_meta( $post_id, '_is_lot_discount', 'no' );
- // } else {
- // update_post_meta( $post_id, '_lot_discount_quantity', $lot_discount_quantity );
- // update_post_meta( $post_id, '_lot_discount_amount', $lot_discount_amount );
- // update_post_meta( $post_id, '_is_lot_discount', $is_lot_discount );
- // }
- // } else if ( $is_lot_discount == 'no' ) {
- // update_post_meta( $post_id, '_lot_discount_quantity', 0 );
- // update_post_meta( $post_id, '_lot_discount_amount', 0 );
- // update_post_meta( $post_id, '_is_lot_discount', 'no' );
- // }
- // Dimensions
- if ( 'no' == $is_virtual ) {
- if ( isset( $_POST['_weight'] ) ) {
- update_post_meta( $post_id, '_weight', ( '' === $_POST['_weight'] ) ? '' : wc_format_decimal( $_POST['_weight'] ) );
- }
- if ( isset( $_POST['_length'] ) ) {
- update_post_meta( $post_id, '_length', ( '' === $_POST['_length'] ) ? '' : wc_format_decimal( $_POST['_length'] ) );
- }
- if ( isset( $_POST['_width'] ) ) {
- update_post_meta( $post_id, '_width', ( '' === $_POST['_width'] ) ? '' : wc_format_decimal( $_POST['_width'] ) );
- }
- if ( isset( $_POST['_height'] ) ) {
- update_post_meta( $post_id, '_height', ( '' === $_POST['_height'] ) ? '' : wc_format_decimal( $_POST['_height'] ) );
- }
- } else {
- update_post_meta( $post_id, '_weight', '' );
- update_post_meta( $post_id, '_length', '' );
- update_post_meta( $post_id, '_width', '' );
- update_post_meta( $post_id, '_height', '' );
- }
- //Save shipping meta data
- update_post_meta( $post_id, '_disable_shipping', stripslashes( isset( $_POST['_disable_shipping'] ) ? $_POST['_disable_shipping'] : 'no' ) );
- if ( isset( $_POST['_overwrite_shipping'] ) && $_POST['_overwrite_shipping'] == 'yes' ) {
- update_post_meta( $post_id, '_overwrite_shipping', stripslashes( $_POST['_overwrite_shipping'] ) );
- } else {
- update_post_meta( $post_id, '_overwrite_shipping', 'no' );
- }
- update_post_meta( $post_id, '_additional_price', stripslashes( isset( $_POST['_additional_price'] ) ? $_POST['_additional_price'] : '' ) );
- update_post_meta( $post_id, '_additional_qty', stripslashes( isset( $_POST['_additional_qty'] ) ? $_POST['_additional_qty'] : '' ) );
- update_post_meta( $post_id, '_dps_processing_time', stripslashes( isset( $_POST['_dps_processing_time'] ) ? $_POST['_dps_processing_time'] : '' ) );
- // Save shipping class
- $product_shipping_class = ( isset( $_POST['product_shipping_class'] ) && $_POST['product_shipping_class'] > 0 && 'external' !== $product_type ) ? absint( $_POST['product_shipping_class'] ) : '';
- wp_set_object_terms( $post_id, $product_shipping_class, 'product_shipping_class' );
- // Cross sells and upsells
- $upsells = isset( $_POST['upsell_ids'] ) ? array_map( 'intval', $_POST['upsell_ids'] ) : array();
- $crosssells = isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', $_POST['crosssell_ids'] ) : array();
- update_post_meta( $post_id, '_upsell_ids', $upsells );
- update_post_meta( $post_id, '_crosssell_ids', $crosssells );
- // Save variations
- if ( 'variable' == $product_type ) {
- dokan_save_variations( $post_id );
- }
- if ( 'grouped' == $product_type && version_compare( WC_VERSION, '2.7', '>' ) ) {
- $product = wc_get_product( $post_id );
- $goroup_product_ids = isset( $_POST['grouped_products'] ) ? array_filter( array_map( 'intval', (array) $_POST['grouped_products'] ) ) : array();
- $product->set_props( array( 'children' => $goroup_product_ids ) );
- $product->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement