Last active
February 21, 2020 09:32
-
-
Save kreamweb/1f43a0519179d4b2d83083f8a6e33348 to your computer and use it in GitHub Desktop.
[POS] Enable options multistock to all products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'init', 'yith_pos_add_meta_to_products' ); | |
| function yith_pos_add_meta_to_products() { | |
| $option = get_option( 'yith_pos_stock_product_enabled', 'no' ); | |
| if ( $option === 'no' ) { | |
| $products = wc_get_products( array( 'limit' => - 1 ) ); | |
| if ( $products ) { | |
| foreach ( $products as $product ) { | |
| update_post_meta( $product->get_id(), '_yith_pos_multistock_enabled', 'yes' ); | |
| } | |
| } | |
| } | |
| add_option( 'yith_pos_stock_product_enabled', 'yes' ); | |
| } | |
| add_action( 'init', 'yith_pos_add_meta_to_product_variations' ); | |
| function yith_pos_add_meta_to_product_variations() { | |
| $option = get_option( 'yith_pos_stock_product_variation_enabled', 'no' ); | |
| if ( $option === 'no' ) { | |
| $products = wc_get_products( array( 'limit' => -1, 'type' =>'variable' ) ); | |
| if ( $products ) { | |
| foreach ( $products as $variable ) { | |
| $variations = $variable->get_available_variations(); | |
| if( $variations ){ | |
| foreach ( $variations as $variation ) { | |
| update_post_meta( $variation['variation_id'], '_yith_pos_multistock_enabled', 'yes' ); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| add_option( 'yith_pos_stock_product_variation_enabled', 'yes' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment