| |
| <?php
|
|
|
|
|
| add_action( 'wcv_after_product_details', 'wcv_product_brand_select2' );
|
|
|
|
|
|
|
|
|
|
|
| function wcv_product_brand_select2( $object_id ) {
|
| $multiple = true;
|
| $exclude = array();
|
| $show_option_none = __( 'Select a brand', 'wcvendors-pro' );
|
| $post_terms = get_the_terms( $object_id, 'product_brand' );
|
| $values = is_array( $post_terms ) ? wp_list_pluck( $post_terms, 'term_id' ) : array();
|
|
|
| WCVendors_Pro_Form_Helper::select( array(
|
| 'post_id' => $object_id,
|
| 'id' => 'product_brand',
|
| 'name' => 'product_brand[]',
|
| 'taxonomy' => 'product_brand',
|
| 'class' => 'category-select2',
|
| 'show_option_none' => $show_option_none,
|
| 'taxonomy_args' => array(
|
| 'hide_empty' => 0,
|
| 'orderby' => 'name',
|
| 'exclude' => $exclude,
|
| ),
|
| 'value' => $values,
|
| 'label' => __( 'Brands', 'wcvendors-pro' ),
|
| 'multiple' => $multiple,
|
| ) );
|
| }
|
|
|
| add_action( 'wcv_save_product', 'save_product_brand' );
|
|
|
|
|
|
|
|
|
|
|
| function save_product_brand( $post_id ) {
|
| if ( ! is_user_logged_in() ) return;
|
|
|
| $product_brand = isset( $_POST['product_brand'] ) ? array_map( 'intval', $_POST['product_brand'] ) : array();
|
| wp_set_post_terms( $post_id, $product_brand, 'product_brand' );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'wcv_after_product_details', 'wcv_product_sizes_select2' );
|
| function wcv_product_sizes_select2( $object_id ) {
|
| $multiple = true;
|
| $exclude = array();
|
| $show_option_none = __( 'Select a size', 'wcvendors-pro' );
|
| $post_terms = get_the_terms( $object_id, 'sizes' );
|
| $values = is_array( $post_terms ) ? wp_list_pluck( $post_terms, 'term_id' ) : array();
|
|
|
| WCVendors_Pro_Form_Helper::select( array(
|
| 'post_id' => $object_id,
|
| 'id' => 'sizes',
|
| 'name' => 'sizes[]',
|
| 'taxonomy' => 'sizes',
|
| 'class' => 'category-select2',
|
| 'show_option_none' => $show_option_none,
|
| 'taxonomy_args' => array(
|
| 'hide_empty' => 0,
|
| 'orderby' => 'name',
|
| 'exclude' => $exclude,
|
| ),
|
| 'value' => $values,
|
| 'label' => __( 'Sizes', 'wcvendors-pro' ),
|
| 'multiple' => $multiple,
|
| ) );
|
| }
|
|
|
|
|
|
|
|
|
| add_action( 'wcv_save_product', 'save_product_sizes' );
|
| function save_product_sizes( $post_id ) {
|
| if ( ! is_user_logged_in() ) return;
|
|
|
| $sizes = isset( $_POST['sizes'] ) ? array_map( 'intval', $_POST['sizes'] ) : array();
|
|
|
| wp_set_post_terms( $post_id, $sizes, 'sizes' );
|
| }
|
|
|
| |
| |
Comments