Last active
October 2, 2018 10:09
-
-
Save grola/baf8224fedf0f13fff97c816195db4b3 to your computer and use it in GitHub Desktop.
WP All Import - Allegro Stock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
iwoocommerce_variation_set_stock
, na których wtyczka "nasłuchuje". Powyższy kod uruchamia wymienione akcje i powoduje aktualizację ilości na aukcji Allegro.