Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
twoelevenjay committed Oct 29, 2024
1 parent fc95262 commit 6dc417f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
20 changes: 10 additions & 10 deletions includes/class-dp-csv-import-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ public function add_column_to_mapping_screen( $columns ) {
* Process the data read from the CSV file.
* This just saves the value in meta data, but you can do anything you want here with the data.
*
* @param WC_Product $object - Product being imported or updated.
* @param WC_Product $product - Product being imported or updated.
* @param array $data - CSV data read for the product.
* @return WC_Product $object
* @return WC_Product $product
*/
public function process_import( $object, $data ) {
public function process_import( $product, $data ) {

if ( ! empty( $data['is_discontinued'] ) ) {
$object->update_meta_data( '_is_discontinued', $data['is_discontinued'] );
$product->update_meta_data( '_is_discontinued', $data['is_discontinued'] );
}
if ( ! empty( $data['discontinued_product_text'] ) ) {
$object->update_meta_data( '_discontinued_product_text', $data['discontinued_product_text'] );
$product->update_meta_data( '_discontinued_product_text', $data['discontinued_product_text'] );
}
if ( ! empty( $data['alt_products'] ) ) {
$object->update_meta_data( '_alt_products', explode( ', ', $data['alt_products'] ) );
$product->update_meta_data( '_alt_products', explode( ', ', $data['alt_products'] ) );
}
if ( ! empty( $data['alt_product_text'] ) ) {
$object->update_meta_data( '_alt_product_text', $data['alt_product_text'] );
$product->update_meta_data( '_alt_product_text', $data['alt_product_text'] );
}
if ( ! empty( $data['hide_from_shop'] ) ) {
$object->update_meta_data( '_hide_from_shop', $data['hide_from_shop'] );
$product->update_meta_data( '_hide_from_shop', $data['hide_from_shop'] );
}
if ( ! empty( $data['hide_from_search'] ) ) {
$object->update_meta_data( '_hide_from_search', $data['hide_from_search'] );
$product->update_meta_data( '_hide_from_search', $data['hide_from_search'] );
}

return $object;
return $product;
}
/**
* Add the custom column to the exporter and the exporter column menu.
Expand Down
14 changes: 9 additions & 5 deletions includes/class-dp-discontinued-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,19 @@ public static function save( $post_id ) {
update_post_meta( $post_id, '_alt_product_text', filter_input( INPUT_POST, '_alt_product_text' ) );
$is_discontinued = filter_input( INPUT_POST, '_is_discontinued' );
if ( $is_discontinued ) {
$terms[] = (int) get_option( 'dp_discontinued_term' );
$terms[] = 'dp-discontinued';
}
$hide_from_shop = filter_input( INPUT_POST, '_hide_from_shop' );
if ( $hide_from_shop ) {
$terms[] = (int) get_option( 'dp_' . $hide_from_shop . '_shop_term' );
if ( 'hide' === $hide_from_shop ) {
$terms[] = 'dp-hide-shop';
} elseif ( 'show' === $hide_from_shop ) {
$terms[] = 'dp-show-shop';
}
$hide_from_search = filter_input( INPUT_POST, '_hide_from_search' );
if ( $hide_from_search ) {
$terms[] = (int) get_option( 'dp_' . $hide_from_search . '_search_term' );
if ( 'hide' === $hide_from_search ) {
$terms[] = 'dp-hide-search';
} elseif ( 'show' === $hide_from_search ) {
$terms[] = 'dp-show-search';
}
wp_set_object_terms( $post_id, $terms, 'product_discontinued' );
}
Expand Down
27 changes: 1 addition & 26 deletions includes/class-dp-shortcode-discontinued.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DP_Shortcode_Discontinued extends WC_Shortcode_Products {
* @param array $query_args Query args.
*/
protected function set_discontinued_products_query_args( &$query_args ) {
$dp_discontinued_term = (int) get_option( 'dp_discontinued_term' );
$dp_discontinued_term = (int) get_option( 'dp_discontinued_term' );
$query_args['tax_query'][] = array(
'taxonomy' => 'product_discontinued',
'field' => 'id',
Expand All @@ -31,28 +31,3 @@ protected function set_discontinued_products_query_args( &$query_args ) {
);
}
}

/**
* List multiple products shortcode.
*
* @param array $atts Attributes.
* @return string
*/
function discontinued_shortcode( $atts ) {
$atts = (array) $atts;
$type = 'discontinued_products';

$shortcode = new DP_Shortcode_Discontinued( $atts, $type );

return $shortcode->get_content();
}



/**
* List multiple products shortcode.
*/
function init_discontinued_shortcode() {
add_shortcode( 'discontinued_products', 'discontinued_shortcode' );
}
add_action( 'init', 'init_discontinued_shortcode' );
23 changes: 23 additions & 0 deletions woocommerce-discontinued-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@

include DP_PATH . 'includes/class-discontinued-products.php';

/**
* List multiple products shortcode.
*
* @param array $atts Attributes.
* @return string
*/
function discontinued_shortcode( $atts ) {
$atts = (array) $atts;
$type = 'discontinued_products';

$shortcode = new DP_Shortcode_Discontinued( $atts, $type );

return $shortcode->get_content();
}

/**
* List multiple products shortcode.
*/
function init_discontinued_shortcode() {
add_shortcode( 'discontinued_products', 'discontinued_shortcode' );
}
add_action( 'init', 'init_discontinued_shortcode' );

// Finally instantiate our plugin class and add it to the set of globals.
$GLOBALS['wc_discontinued_products'] = new Discontinued_Products();
}

0 comments on commit 6dc417f

Please sign in to comment.