Show the stock status option from product settings “Inventory” to “General” tab in Woocommerce
up vote
1
down vote
favorite
In woocommerce by default, the stock status
option is under the "inventory" tab.
How I can show the exact option under the general
tab?
Searching, I stumble across this code inside woocommerce/includes/abstracts/abstract-wc-product.php
:
public function set_stock_status( $status = 'instock' ) {
$valid_statuses = wc_get_product_stock_status_options();
if ( isset( $valid_statuses[ $status ] ) ) {
$this->set_prop( 'stock_status', $status );
} else {
$this->set_prop( 'stock_status', 'instock' );
}
}
Then inside functions.php
, I have added:
add_action( 'woocommerce_product_options_general_product_data', 'check_stock_status' );`
But nothing happen. May be I'm calling the wrong function.
P/S : I'm using WC 2.6.4
php wordpress woocommerce product hook-woocommerce
add a comment |
up vote
1
down vote
favorite
In woocommerce by default, the stock status
option is under the "inventory" tab.
How I can show the exact option under the general
tab?
Searching, I stumble across this code inside woocommerce/includes/abstracts/abstract-wc-product.php
:
public function set_stock_status( $status = 'instock' ) {
$valid_statuses = wc_get_product_stock_status_options();
if ( isset( $valid_statuses[ $status ] ) ) {
$this->set_prop( 'stock_status', $status );
} else {
$this->set_prop( 'stock_status', 'instock' );
}
}
Then inside functions.php
, I have added:
add_action( 'woocommerce_product_options_general_product_data', 'check_stock_status' );`
But nothing happen. May be I'm calling the wrong function.
P/S : I'm using WC 2.6.4
php wordpress woocommerce product hook-woocommerce
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In woocommerce by default, the stock status
option is under the "inventory" tab.
How I can show the exact option under the general
tab?
Searching, I stumble across this code inside woocommerce/includes/abstracts/abstract-wc-product.php
:
public function set_stock_status( $status = 'instock' ) {
$valid_statuses = wc_get_product_stock_status_options();
if ( isset( $valid_statuses[ $status ] ) ) {
$this->set_prop( 'stock_status', $status );
} else {
$this->set_prop( 'stock_status', 'instock' );
}
}
Then inside functions.php
, I have added:
add_action( 'woocommerce_product_options_general_product_data', 'check_stock_status' );`
But nothing happen. May be I'm calling the wrong function.
P/S : I'm using WC 2.6.4
php wordpress woocommerce product hook-woocommerce
In woocommerce by default, the stock status
option is under the "inventory" tab.
How I can show the exact option under the general
tab?
Searching, I stumble across this code inside woocommerce/includes/abstracts/abstract-wc-product.php
:
public function set_stock_status( $status = 'instock' ) {
$valid_statuses = wc_get_product_stock_status_options();
if ( isset( $valid_statuses[ $status ] ) ) {
$this->set_prop( 'stock_status', $status );
} else {
$this->set_prop( 'stock_status', 'instock' );
}
}
Then inside functions.php
, I have added:
add_action( 'woocommerce_product_options_general_product_data', 'check_stock_status' );`
But nothing happen. May be I'm calling the wrong function.
P/S : I'm using WC 2.6.4
php wordpress woocommerce product hook-woocommerce
php wordpress woocommerce product hook-woocommerce
edited Nov 12 at 4:06
asked Nov 11 at 7:32
Nazrin Noorzan
126112
126112
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24
add a comment |
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
To display a duplicated Stock status setting select field in Woocommerce "Product data" metabox under "General" tab, you can use one of the following available action hooks:
woocommerce_product_options_general_product_data
woocommerce_product_options_pricing
(hidden on some product types)
woocommerce_product_options_downloads
(hidden if product is not downloadable)
woocommerce_product_options_tax
(hidden on some product types)
The code (commented the "wrapper_class" argument to force the display):
add_action( 'woocommerce_product_options_general_product_data', 'stock_status_in_general_options_settings' );
function stock_status_in_general_options_settings() {
global $post, $product_object;
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
// 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
}
Code goes in function.php file of your active child theme (active theme).
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
To display a duplicated Stock status setting select field in Woocommerce "Product data" metabox under "General" tab, you can use one of the following available action hooks:
woocommerce_product_options_general_product_data
woocommerce_product_options_pricing
(hidden on some product types)
woocommerce_product_options_downloads
(hidden if product is not downloadable)
woocommerce_product_options_tax
(hidden on some product types)
The code (commented the "wrapper_class" argument to force the display):
add_action( 'woocommerce_product_options_general_product_data', 'stock_status_in_general_options_settings' );
function stock_status_in_general_options_settings() {
global $post, $product_object;
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
// 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
}
Code goes in function.php file of your active child theme (active theme).
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
add a comment |
up vote
1
down vote
To display a duplicated Stock status setting select field in Woocommerce "Product data" metabox under "General" tab, you can use one of the following available action hooks:
woocommerce_product_options_general_product_data
woocommerce_product_options_pricing
(hidden on some product types)
woocommerce_product_options_downloads
(hidden if product is not downloadable)
woocommerce_product_options_tax
(hidden on some product types)
The code (commented the "wrapper_class" argument to force the display):
add_action( 'woocommerce_product_options_general_product_data', 'stock_status_in_general_options_settings' );
function stock_status_in_general_options_settings() {
global $post, $product_object;
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
// 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
}
Code goes in function.php file of your active child theme (active theme).
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
add a comment |
up vote
1
down vote
up vote
1
down vote
To display a duplicated Stock status setting select field in Woocommerce "Product data" metabox under "General" tab, you can use one of the following available action hooks:
woocommerce_product_options_general_product_data
woocommerce_product_options_pricing
(hidden on some product types)
woocommerce_product_options_downloads
(hidden if product is not downloadable)
woocommerce_product_options_tax
(hidden on some product types)
The code (commented the "wrapper_class" argument to force the display):
add_action( 'woocommerce_product_options_general_product_data', 'stock_status_in_general_options_settings' );
function stock_status_in_general_options_settings() {
global $post, $product_object;
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
// 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
}
Code goes in function.php file of your active child theme (active theme).
To display a duplicated Stock status setting select field in Woocommerce "Product data" metabox under "General" tab, you can use one of the following available action hooks:
woocommerce_product_options_general_product_data
woocommerce_product_options_pricing
(hidden on some product types)
woocommerce_product_options_downloads
(hidden if product is not downloadable)
woocommerce_product_options_tax
(hidden on some product types)
The code (commented the "wrapper_class" argument to force the display):
add_action( 'woocommerce_product_options_general_product_data', 'stock_status_in_general_options_settings' );
function stock_status_in_general_options_settings() {
global $post, $product_object;
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
// 'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
}
Code goes in function.php file of your active child theme (active theme).
answered Nov 11 at 14:14
LoicTheAztec
80.6k125993
80.6k125993
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
add a comment |
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
I got this error "Fatal error: Call to a member function get_stock_status() on null in..." . I think it's because I'm using WC 2.6.4 .Sorry forgot to highlight that.
– Nazrin Noorzan
Nov 12 at 3:52
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
Anyway I changed global $product_object to $product and set the value to $product->stock_status( 'edit' ), and this time the error is "Fatal error: Call to a member function stock_status() on array in..." . Clearly I'm still using some new WC 3.x syntax here but I can't figure it out.
– Nazrin Noorzan
Nov 12 at 3:57
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
@NazrinNoorzan My answer code is made to work only with Woocommerce 3+… You didn't explicitly restricted your question to Woocommerce 2.6.x and mostly nobody uses outdated Woocommerce version 2.6.x. I will try to add later a version code for Woocommerce 2.6.x …
– LoicTheAztec
Nov 12 at 9:10
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
yeah my bad. The reason why I stick with the old version is because if I update it, there are a lot of things broken. Anyway, have you got the answer for WC 2.6.x version?
– Nazrin Noorzan
Nov 20 at 16:27
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246712%2fshow-the-stock-status-option-from-product-settings-inventory-to-general-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@LoicTheAztec im not trying to move it, just to duplicate the option. If it is hardcoded, which file?
– Nazrin Noorzan
Nov 11 at 12:24