Skip to content

Commit

Permalink
Merge pull request #96 from pinalj/add-filter
Browse files Browse the repository at this point in the history
Add filters
  • Loading branch information
pinalj authored Mar 20, 2024
2 parents ca4267c + 570382f commit a664e5e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
16 changes: 11 additions & 5 deletions includes/admin/class-quotes-wc-general-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function add_settings( $settings ) {
'id' => 'qwc_cart_settings_section',
),
);
$settings = apply_filters( 'qwc_lite_general_settings', $settings );
return $settings;
}

Expand Down Expand Up @@ -222,12 +223,17 @@ public function qwc_all_quotes( $quote_setting_name, $quote_setting_value, $loop
);
$product_list = get_posts( $args );

foreach ( $product_list as $k => $value ) {

// Product ID.
$theid = $value->ID;
update_post_meta( $theid, $quote_setting_name, $quote_setting_value );
switch ( $quote_setting_name ) {
case 'qwc_enable_quotes':
$product_list = apply_filters( 'qwc_enable_quote_bulk', $product_list, $quote_setting_value );
break;
case 'qwc_display_prices':
$product_list = apply_filters( 'qwc_enable_price_display_bulk', $product_list, $quote_setting_value );
break;
default:
break;
}
qwc_bulk_edit_setting_by_id( $product_list, $quote_setting_name, $quote_setting_value );

wp_reset_postdata();

Expand Down
25 changes: 25 additions & 0 deletions includes/qwc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,28 @@ function qwc_is_hpos_enabled() {

return false;
}

/**
* Modify product level settings in bulk.
*
* @param array $products_list - List of products.
* @param string $quote_setting_name - Setting meta key.
* @param string $quote_setting_value - Settings meta value.
*
* @since 2.2
*/
function qwc_bulk_edit_setting_by_id( $products_list, $quote_setting_name, $quote_setting_value ) {

if ( '' === $quote_setting_name ) {
return;
}

if ( is_array( $products_list ) && count( $products_list ) > 0 ) {
foreach ( $products_list as $k => $value ) {

// Product ID.
$theid = isset( $value->ID ) ? $value->ID : $value;
update_post_meta( $theid, $quote_setting_name, $quote_setting_value );
}
}
}

0 comments on commit a664e5e

Please sign in to comment.