• Resolved wpfighter

    (@wpfighter)


    Is there a way we can reproduce all the woo commerce metas in custom post types say: “Themes” custom post type.

    If yes, then can someone guide me who has already tried.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Example:

      // add custom fields to the class post type
      add_action( 'admin_init', 'add_attendance_fields' );
      function add_attendance_fields() {
        // add_meta_box( id, title, callback, screen, context, priority, $args );
        $args = array();
        add_meta_box( 'attendance_meta_box', __( 'Attendance data', 'academy' ), 'attendance_meta_box', 'attendance', 'normal', 'default', $args );
      } // end function
    

    For your question, id and callback would have to be obtained from the WooCommerce code, and will be different for each metabox that you want. screen is your custom post type’s screen name. context is normal, side or advanced and relates to the position of the metabox on the page. $args can be an empty array.

    The chances of it working are slim because the metaboxes may be relying on other variables that should already have been setup be in a normal WooCommerce page. You may need to take the WooCommerce callback functions, copy them and recode them to suit.

    This would be a non-trivial development.

    Thread Starter wpfighter

    (@wpfighter)

    In general, assigning particular meta to more than one post type is not difficult.

    	$cmb = new_cmb2_box( array(
    		'id'            => 'singhal_metabox_2',
    		'title'         => esc_html__( 'Select Layouts', 'text_domain' ),
    		'object_types'  => array( 'post', 'page', 'themes' ), // Post type
    		'context'       => 'normal',
    		'priority'      => 'high',
    		'show_names'    => true, // Show field names on the left
    		// 'cmb_styles' => false, // false to disable the CMB stylesheet
    		// 'closed'     => true, // Keep the metabox closed by default
    	) );
    

    But what if we want to reproduce all woocommerce metas in custom post types? Would that be possible?

    • This reply was modified 5 years, 9 months ago by wpfighter.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Reproduce Woo commerce’s all product meta in custom post types’ is closed to new replies.