具有自定义帖子类型的现有电子商务插件

时间:2014-03-08 作者:Mohit Kumar

我正在开发一个解决方案,该解决方案销售一项服务(不能归类为产品)。我已经开发了自定义的帖子类型和分类法,但我不想通过为此目的添加支付网关来重新发明轮子。是否有任何方法可以自定义任何现有电子商务插件中的“产品”帖子类型。

感谢您的支持

2 个回复
最合适的回答,由SO网友:Sormano 整理而成

您应该下载带有内置支付网关的en use WooCommerce

您可以添加具有以下内容的产品类型:

function my_add_product_type( $types ) {
    return $types["service"] = "Service";
}
add_filter( "product_type_selector", "my_add_product_type" );

SO网友:helgatheviking

如果你的帖子类型被称为“产品”,那么如果你删除注册你帖子类型的代码并激活,比如WooCommerce,插件应该能识别这些帖子。但是,您需要配置一些元字段。

根据您的评论,WooCommerce注册product 具有以下相关代码的职位类型:

if ( post_type_exists(\'product\') )
    return;

do_action( \'woocommerce_register_post_type\' );

$permalinks        = get_option( \'woocommerce_permalinks\' );
$product_permalink = empty( $permalinks[\'product_base\'] ) ? _x( \'product\', \'slug\', \'woocommerce\' ) : $permalinks[\'product_base\'];

register_post_type( "product",
    apply_filters( \'woocommerce_register_post_type_product\',
        array(
            \'labels\' => array(
                    \'name\'                  => __( \'Products\', \'woocommerce\' ),
                    \'singular_name\'         => __( \'Product\', \'woocommerce\' ),
                    \'menu_name\'             => _x( \'Products\', \'Admin menu name\', \'woocommerce\' ),
                    \'add_new\'               => __( \'Add Product\', \'woocommerce\' ),
                    \'add_new_item\'          => __( \'Add New Product\', \'woocommerce\' ),
                    \'edit\'                  => __( \'Edit\', \'woocommerce\' ),
                    \'edit_item\'             => __( \'Edit Product\', \'woocommerce\' ),
                    \'new_item\'              => __( \'New Product\', \'woocommerce\' ),
                    \'view\'                  => __( \'View Product\', \'woocommerce\' ),
                    \'view_item\'             => __( \'View Product\', \'woocommerce\' ),
                    \'search_items\'          => __( \'Search Products\', \'woocommerce\' ),
                    \'not_found\'             => __( \'No Products found\', \'woocommerce\' ),
                    \'not_found_in_trash\'    => __( \'No Products found in trash\', \'woocommerce\' ),
                    \'parent\'                => __( \'Parent Product\', \'woocommerce\' )
                ),
            \'description\'           => __( \'This is where you can add new products to your store.\', \'woocommerce\' ),
            \'public\'                => true,
            \'show_ui\'               => true,
            \'capability_type\'       => \'product\',
            \'map_meta_cap\'          => true,
            \'publicly_queryable\'    => true,
            \'exclude_from_search\'   => false,
            \'hierarchical\'          => false, // Hierarchical causes memory issues - WP loads all records!
            \'rewrite\'               => $product_permalink ? array( \'slug\' => untrailingslashit( $product_permalink ), \'with_front\' => false, \'feeds\' => true ) : false,
            \'query_var\'             => true,
            \'supports\'              => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'comments\', \'custom-fields\', \'page-attributes\' ),
            \'has_archive\'           => ( $shop_page_id = wc_get_page_id( \'shop\' ) ) && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : \'shop\',
            \'show_in_nav_menus\'     => true
        )
    )
);
您将注意到register_post_type 可通过woocommerce_register_post_type_product 滤器

因此,如果您想将所有后端标签更改为“服务”,可以执行以下操作:

function wpa_137268( $args ){
    $args[\'labels\'] = array(
        \'name\'                  => __( \'Services\' ),
        \'singular_name\'         => __( \'Service\' ),
        \'menu_name\'             => _x( \'Services\', \'Admin menu name\' ),
        \'add_new\'               => __( \'Add Service\' ),
        \'add_new_item\'          => __( \'Add New Service\' ),
        \'edit\'                  => __( \'Edit\' ),
        \'edit_item\'             => __( \'Edit Service\' ),
        \'new_item\'              => __( \'New Service\' ),
        \'view\'                  => __( \'View Service\' ),
        \'view_item\'             => __( \'View Service\' ),
        \'search_items\'          => __( \'Search Services\' ),
        \'not_found\'             => __( \'No Services found\' ),
        \'not_found_in_trash\'    => __( \'No Services found in trash\' ),
        \'parent\'                => __( \'Parent Service\' )
    );
    return $args;
}
add_filter( \'woocommerce_register_post_type_product\', \'wpa_137268\' );
你可以从那里推断出你想要改变的任何其他东西。

结束

相关推荐