Created
August 29, 2022 15:42
-
-
Save idokd/9ddf489a055d65793b24d4457ec1c02a to your computer and use it in GitHub Desktop.
Enable Woocommerce Product Vendors Metabox on Shop Order woocommerce-product-vendors
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 Woocommerce Vendors Taxonomy to WC Order and enable Metabox on Shop Order | |
| add_action( 'init', function() { | |
| if ( defined( 'WC_PRODUCT_VENDORS_TAXONOMY' ) ) register_taxonomy_for_object_type( WC_PRODUCT_VENDORS_TAXONOMY, 'shop_order' ); | |
| } ); | |
| add_action( 'save_post', 'wcpv_product_vendors_save_order_vendor' ); | |
| function wcpv_product_vendors_save_order_vendor( $order_id ) { | |
| if ( !defined( 'WC_PRODUCT_VENDORS_TAXONOMY' ) ) return; | |
| if ( ! current_user_can( 'manage_woocommerce' ) ) { | |
| return; | |
| } | |
| // if not a show_order bail | |
| if ( 'shop_order' !== get_post_type( $order_id ) ) { | |
| return; | |
| } | |
| $term = ! empty( $_POST[ 'wcpv_product_term' ] ) ? absint( $_POST[ 'wcpv_product_term' ] ) : ''; | |
| wp_set_object_terms( $order_id, $term, WC_PRODUCT_VENDORS_TAXONOMY ); | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment