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










share|improve this question
























  • @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















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










share|improve this question
























  • @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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • @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












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).



enter image description here






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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).



enter image description here






share|improve this answer





















  • 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















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).



enter image description here






share|improve this answer





















  • 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













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).



enter image description here






share|improve this answer












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).



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 14:14









LoicTheAztec

80.7k125993




80.7k125993












  • 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










  • 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


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation