', 'title' => __( 'Affiliate product', 'woocommerce' ), 'description' => __( 'A link to a product sold on a different website, e.g. brand collab.', 'woocommerce' ), 'order' => 30, 'icon' => 'link', 'layout_template_id' => 'simple-product', 'product_data' => array( 'type' => 'external', ), ) ); return $templates; } /** * Create default product template by custom product type if it does not have a * template associated yet. * * @param array $templates The registered product templates. * @return array The new templates. */ private function create_default_product_template_by_custom_product_type( array $templates ) { // Getting the product types registered via the classic editor. $registered_product_types = wc_get_product_types(); $custom_product_types = array_filter( $registered_product_types, function ( $product_type ) { return ! in_array( $product_type, $this->supported_product_types, true ); }, ARRAY_FILTER_USE_KEY ); $templates_with_product_type = array_filter( $templates, function ( $template ) { $product_data = $template->get_product_data(); return ! is_null( $product_data ) && array_key_exists( 'type', $product_data ); } ); $custom_product_types_on_templates = array_map( function ( $template ) { $product_data = $template->get_product_data(); return $product_data['type']; }, $templates_with_product_type ); foreach ( $custom_product_types as $product_type => $title ) { if ( in_array( $product_type, $custom_product_types_on_templates, true ) ) { continue; } $templates[] = new ProductTemplate( array( 'id' => $product_type . '-product-template', 'title' => $title, 'product_data' => array( 'type' => $product_type, ), ) ); } return $templates; } /** * Register layout templates. */ public function register_layout_templates() { $layout_template_registry = wc_get_container()->get( LayoutTemplateRegistry::class ); if ( ! $layout_template_registry->is_registered( 'simple-product' ) ) { $layout_template_registry->register( 'simple-product', 'product-form', SimpleProductTemplate::class ); } if ( ! $layout_template_registry->is_registered( 'product-variation' ) ) { $layout_template_registry->register( 'product-variation', 'product-form', ProductVariationTemplate::class ); } } /** * Register product templates. */ public function register_product_templates() { /** * Allows for new product template registration. * * @since 8.5.0 */ $this->product_templates = apply_filters( 'woocommerce_product_editor_product_templates', $this->get_default_product_templates() ); $this->product_templates = $this->create_default_product_template_by_custom_product_type( $this->product_templates ); usort( $this->product_templates, function ( $a, $b ) { return $a->get_order() - $b->get_order(); } ); $this->redirection_controller->set_product_templates( $this->product_templates ); } /** * Register user metas. */ public function register_user_metas() { register_rest_field( 'user', 'metaboxhidden_product', array( 'get_callback' => function ( $object, $attr ) { $hidden = get_user_meta( $object['id'], $attr, true ); if ( is_array( $hidden ) ) { // Ensures to always return a string array. return array_values( $hidden ); } return array( 'postcustom' ); }, 'update_callback' => function ( $value, $object, $attr ) { // Update the field/meta value. update_user_meta( $object->ID, $attr, $value ); }, 'schema' => array( 'type' => 'array', 'description' => __( 'The metaboxhidden_product meta from the user metas.', 'woocommerce' ), 'items' => array( 'type' => 'string', ), 'arg_options' => array( 'sanitize_callback' => 'wp_parse_list', 'validate_callback' => 'rest_validate_request_arg', ), ), ) ); } } مقایسه محصولات
سبد خرید 0

موجود

توضیحات

برگشت به بالا
سوالی دارید؟ با ما صحبت کنید!
مکالمه را شروع کنید
سلام! برای چت در WhatsApp پرسنل پشتیبانی که میخواهید با او صحبت کنید را انتخاب کنید
ما معمولاً در چند دقیقه پاسخ می دهیم