Skip to content

Instantly share code, notes, and snippets.

@grola
Last active October 2, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grola/baf8224fedf0f13fff97c816195db4b3 to your computer and use it in GitHub Desktop.
Save grola/baf8224fedf0f13fff97c816195db4b3 to your computer and use it in GitHub Desktop.
WP All Import - Allegro Stock
<?php
add_action( 'pmxi_saved_post', 'wpdesk_pmxi_saved_post_trigger_set_stock' );
/**
* Trigger set stock for product.
*
* @param int $post_id Post id.
*/
function wpdesk_pmxi_saved_post_trigger_set_stock( $post_id ) {
if ( function_exists( 'wc_get_product' ) ) {
$product = wc_get_product( $post_id );
if ( $product ) {
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock', $product );
} else {
do_action( 'woocommerce_product_set_stock', $product );
}
}
}
}
@grola
Copy link
Author

grola commented Oct 2, 2018

Powyższy kod należy dodać do pliku functions.php motywu.

Działanie: podczas importu produktów przy użyciu wtyczki WP All Import stany magazynowe produktu są aktualizowane funkcją update_post_meta z pominięciem mechanizmów WooCommerce.
Aby wtyczka Allegro zmodyfikowała ilość na wystawionej aukcji dla danego produktu należy ją poinformować, że nastąpiła zmiana stanu magazynowego. Jest to możliwe poprzez akcje woocommerce_product_set_stock i woocommerce_variation_set_stock, na których wtyczka "nasłuchuje". Powyższy kod uruchamia wymienione akcje i powoduje aktualizację ilości na aukcji Allegro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment