我做了一个cron作业来运行一个函数,但该函数不会运行。我确实运行了函数内部的代码,在外部查看它是否工作,它确实工作了,但如果在函数内部,它就什么都不会做。
我的钩子add_action( \'Stock_Sync_Hook\', \'Full_Stock_Sync\' );
和我的功能
function Full_Stock_Sync() {
$MasterwayRequest = new MasterwayRequest($this->APIKey, $this->APISecret);
$CompanyCode = $this->CompanyCode;
$CodArmazem = get_option(\'wc_mw_warehouse\');
$CodLocalizacao = get_option(\'wc_mw_location\');
$Stocks = $MasterwayRequest->stock_sync($CompanyCode, $CodArmazem, $CodLocalizacao);
if ($Stocks) {
global $woocommerce;
foreach ( $Stocks as $Stock ) {
$StockDisponivel = $Stock[\'StockDisponivel\'];
$CodProduto = $Stock[\'CodProduto\'];
$ID = wc_get_product_id_by_sku($CodProduto);
if ($ID)
{
$Product = new WC_Product( $ID );
$NewStock = wc_update_product_stock( $Product, $StockDisponivel);
echo $NewStock;
unset($ID);
}
else
{
$Product = new WC_Product( $CodProduto );
$NewStock = wc_update_product_stock( $Product, $StockDisponivel);
echo $NewStock;
}
$Product = new WC_Product( $CodProduto );
$wc_sku = $Product->get_sku();
if($wc_sku){
$ID = wc_get_product_id_by_sku($wc_sku);
$Product = new WC_Product( $ID );
unset($wc_sku);
}
$NewStock = wc_update_product_stock( $Product, $StockDisponivel);
echo $NewStock;
}//#FOREACH
}//#IF STOCKS
}//#StockSync
cron作业处于活动状态,但功能无法运行,我尝试将时间更改为10秒左右,但仍然没有任何结果。你知道为什么它不会运行吗?