Wordpress 如何更改主元数据库中的默认产品类型

Wordpress 如何更改主元数据库中的默认产品类型,wordpress,woocommerce,Wordpress,Woocommerce,我需要将主WooCommerce元数据库中的默认产品类型从“简单产品”更改为“简单订阅”,有人知道如何实现这一点吗 我试图使用我在源代码中找到的过滤器,但最接近我的是添加了自定义产品类型,这显然不是我想要的 谢谢。您忽略了正确的过滤器,default\u product\u type,它位于WC\u Meta\u Box\u product\u Data类的输出方法中: if ( $terms = wp_get_object_terms( $post->ID, 'product_type'

我需要将主WooCommerce元数据库中的默认产品类型从“简单产品”更改为“简单订阅”,有人知道如何实现这一点吗

我试图使用我在源代码中找到的过滤器,但最接近我的是添加了自定义产品类型,这显然不是我想要的


谢谢。

您忽略了正确的过滤器,
default\u product\u type
,它位于
WC\u Meta\u Box\u product\u Data
类的
输出方法中:

if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) {
    $product_type = sanitize_title( current( $terms )->name );
} else {
    $product_type = apply_filters( 'default_product_type', 'simple' );
}
要对其进行过滤,请执行以下操作:

function so_27657057_default_product_type(){
  return "subscription";
}
add_action( 'default_product_type', 'so_27657057_default_product_type' );

您可能希望通过一些条件逻辑来检查订阅特定类的存在,但是如果您知道它总是存在的话,那就没什么大不了的了

您忽略了正确的过滤器,
default\u product\u type
,它位于
WC\u Meta\u Box\u product\u Data
类的
output
方法中:

if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) {
    $product_type = sanitize_title( current( $terms )->name );
} else {
    $product_type = apply_filters( 'default_product_type', 'simple' );
}
要对其进行过滤,请执行以下操作:

function so_27657057_default_product_type(){
  return "subscription";
}
add_action( 'default_product_type', 'so_27657057_default_product_type' );

您可能希望通过一些条件逻辑来检查订阅特定类的存在,但是如果您知道它总是存在的话,那就没什么大不了的了

您忽略了正确的过滤器,
default\u product\u type
,它位于
WC\u Meta\u Box\u product\u Data
类的
output
方法中:

if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) {
    $product_type = sanitize_title( current( $terms )->name );
} else {
    $product_type = apply_filters( 'default_product_type', 'simple' );
}
要对其进行过滤,请执行以下操作:

function so_27657057_default_product_type(){
  return "subscription";
}
add_action( 'default_product_type', 'so_27657057_default_product_type' );

您可能希望通过一些条件逻辑来检查订阅特定类的存在,但是如果您知道它总是存在的话,那就没什么大不了的了

您忽略了正确的过滤器,
default\u product\u type
,它位于
WC\u Meta\u Box\u product\u Data
类的
output
方法中:

if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) {
    $product_type = sanitize_title( current( $terms )->name );
} else {
    $product_type = apply_filters( 'default_product_type', 'simple' );
}
要对其进行过滤,请执行以下操作:

function so_27657057_default_product_type(){
  return "subscription";
}
add_action( 'default_product_type', 'so_27657057_default_product_type' );

您可能希望通过一些条件逻辑来检查订阅特定类的存在,但是如果您知道它总是存在的话,那就没什么大不了的了

谢谢大家提出的宝贵建议。 WooThemes支持还添加了一个解决方案,我最终使用了该解决方案,而且效果良好:

add_filter( 'product_type_selector', 'mw_custom_product_type_change', 20 );
function mw_custom_product_type_change( $product_types ) {
    $new_array = array( 'booking' => $product_types['booking'] );
    $product_types = $new_array;
    return $product_types;
}

@helgatheviking的方法看起来也很优雅,所以我也会尝试一下。再次感谢。

谢谢大家提出的宝贵建议。 WooThemes支持还添加了一个解决方案,我最终使用了该解决方案,而且效果良好:

add_filter( 'product_type_selector', 'mw_custom_product_type_change', 20 );
function mw_custom_product_type_change( $product_types ) {
    $new_array = array( 'booking' => $product_types['booking'] );
    $product_types = $new_array;
    return $product_types;
}

@helgatheviking的方法看起来也很优雅,所以我也会尝试一下。再次感谢。

谢谢大家提出的宝贵建议。 WooThemes支持还添加了一个解决方案,我最终使用了该解决方案,而且效果良好:

add_filter( 'product_type_selector', 'mw_custom_product_type_change', 20 );
function mw_custom_product_type_change( $product_types ) {
    $new_array = array( 'booking' => $product_types['booking'] );
    $product_types = $new_array;
    return $product_types;
}

@helgatheviking的方法看起来也很优雅,所以我也会尝试一下。再次感谢。

谢谢大家提出的宝贵建议。 WooThemes支持还添加了一个解决方案,我最终使用了该解决方案,而且效果良好:

add_filter( 'product_type_selector', 'mw_custom_product_type_change', 20 );
function mw_custom_product_type_change( $product_types ) {
    $new_array = array( 'booking' => $product_types['booking'] );
    $product_types = $new_array;
    return $product_types;
}

@helgatheviking的方法看起来也很优雅,所以我也会尝试一下。再次感谢。

helgatheviking提到的“默认产品类型”在Woocommerce中不再可用

@路易斯·马丁斯自己的解决方案只有在排除其他产品类型的情况下才有效

我试图找出如何使用代码挂钩将新产品的后备产品类型从“简单”更改为其他类型, 但是无法通过PHP找到我的方法

相反,我通过“admin_enqueue_scripts”操作将jQuery排入队列来实现这一点:

jQuery(function() {

    if ( document.location.href.indexOf( 'post-new.php?post_type=product' ) !== -1 ) {

        // If we have a page of an initially created product(an auto draft)

        // Force the default product type to 'variable'
        $( '#product-type' )
            .val( 'subscription' )
            .trigger( 'change' );

    }

});

@helgatheviking提到的“默认产品类型”在Woocommerce中不再可用

@路易斯·马丁斯自己的解决方案只有在排除其他产品类型的情况下才有效

我试图找出如何使用代码挂钩将新产品的后备产品类型从“简单”更改为其他类型, 但是无法通过PHP找到我的方法

相反,我通过“admin_enqueue_scripts”操作将jQuery排入队列来实现这一点:

jQuery(function() {

    if ( document.location.href.indexOf( 'post-new.php?post_type=product' ) !== -1 ) {

        // If we have a page of an initially created product(an auto draft)

        // Force the default product type to 'variable'
        $( '#product-type' )
            .val( 'subscription' )
            .trigger( 'change' );

    }

});

@helgatheviking提到的“默认产品类型”在Woocommerce中不再可用

@路易斯·马丁斯自己的解决方案只有在排除其他产品类型的情况下才有效

我试图找出如何使用代码挂钩将新产品的后备产品类型从“简单”更改为其他类型, 但是无法通过PHP找到我的方法

相反,我通过“admin_enqueue_scripts”操作将jQuery排入队列来实现这一点:

jQuery(function() {

    if ( document.location.href.indexOf( 'post-new.php?post_type=product' ) !== -1 ) {

        // If we have a page of an initially created product(an auto draft)

        // Force the default product type to 'variable'
        $( '#product-type' )
            .val( 'subscription' )
            .trigger( 'change' );

    }

});

@helgatheviking提到的“默认产品类型”在Woocommerce中不再可用

@路易斯·马丁斯自己的解决方案只有在排除其他产品类型的情况下才有效

我试图找出如何使用代码挂钩将新产品的后备产品类型从“简单”更改为其他类型, 但是无法通过PHP找到我的方法

相反,我通过“admin_enqueue_scripts”操作将jQuery排入队列来实现这一点:

jQuery(function() {

    if ( document.location.href.indexOf( 'post-new.php?post_type=product' ) !== -1 ) {

        // If we have a page of an initially created product(an auto draft)

        // Force the default product type to 'variable'
        $( '#product-type' )
            .val( 'subscription' )
            .trigger( 'change' );

    }

});

如果你只想改变名字,那么你可以通过插件自己做。这位于第39行附近的
wp-content>plugins>woocommerce>includes>admin>metabox>class-wc-metabox-product-data.php
。注意:这不是一个很好的方法。但是如果你很匆忙,你可以选择这种方法。如果你只想改变名字,那么你可以通过插件自己来做。这位于第39行附近的
wp-content>plugins>woocommerce>includes>admin>metabox>class-wc-metabox-product-data.php
。注意:这不是一个很好的方法。但是如果你很匆忙,你可以选择这种方法。如果你只想改变名字,那么你可以通过插件自己来做。这位于第39行附近的
wp-content>plugins>woocommerce>includes>admin>metabox>class-wc-metabox-product-data.php
。注意:这不是一个很好的方法。但是如果你很匆忙,你可以选择这种方法。如果你只想改变名字,那么你可以通过插件自己来做。这位于
wp content>plugins>