Skip to content

Instantly share code, notes, and snippets.

@PepDevils
Created December 14, 2017 12:25
Show Gist options
  • Save PepDevils/1b6a4430dcb6dca71c16ab715aaad631 to your computer and use it in GitHub Desktop.
Save PepDevils/1b6a4430dcb6dca71c16ab715aaad631 to your computer and use it in GitHub Desktop.
/*
Wordpress - woocomerce
Como mudar o estado do produto (Pode ser Comprado / Não pode ser comprado), apartir do seu estado de stock (Brevemente/Sem stock/com stock/etc...);
Estudar Hooks do wordpress.
Estes podem ser interceptados por Actions ou Filters
*/
//tutoriais wordpress
https://www.bloglite.net/entendendo-os-actions-filters-e-hooks-do-wordpress/
https://felipeelia.com.br/hooks-no-wordpress-actions-e-filters/
//perceber as paginas e onde corre cada hook em woocommerce
https://businessbloomer.com/storefront-theme-visual-hook-guide/
https://businessbloomer.com/woocommerce-tips/visual-hook-series/
https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/#
https://businessbloomer.com/woocommerce-visual-hook-guide-cart-page/
https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/
//todos os hooks do woocomerce
https://docs.woocommerce.com/wc-apidocs/hook-docs.html
//alguns exemplos
https://www.cloudways.com/blog/how-to-remove-hide-or-disable-add-to-cart-button-in-woocommerce/
http://developergang.com/remove-add-cart-button-specific-product/
https://businessbloomer.com/woocommerce-remove-add-cart-add-view-product-loop/
https://wisdmlabs.com/blog/the-right-way-to-hide-add-to-cart-button-in-woocommerce/
https://theme.co/apex/forums/topic/woocommerce-stick-to-popup/
//melhor exemplo
https://stackoverflow.com/questions/17259052/modify-woocommerce-is-purchasable
//codigo
// adicionar ao functions.php do tema
function changePurchasableProductByStockStatus($is_purchasable, $product) {
$stock_status = get_post_meta($product->id , '_stock_status' , true );
if($stock_status == "onhold"){ // se produto está em brevemente
return false;
}else{ //caso não esteja
return true;
}
}
add_filter('woocommerce_is_purchasable', 'changePurchasableProductByStockStatus', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment