2kb Amazon DropShip Manager requires 2kb Amazon Affiliate Store Plugin v2.0.0 or bigger. Install it or open in wordpress.org
', admin_url() . 'plugin-install.php?tab=search&s=2kb+amazon+affiliate+store', 'https://wordpress.org/plugins/2kb-amazon-affiliates-store/' ); } return; } if(!class_exists('WP_List_Table')){ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); } require_once KbAmazonDropShipManagerPluginPath . 'KbAmazonDropShipManagerController.php'; require_once KbAmazonDropShipManagerPluginPath . 'KbAmazonDropShipManagerAdmin.php'; require_once KbAmazonDropShipManagerPluginPath . 'functions.php'; add_filter('getKbAmzDefaultOptions', 'KbAmazonDropShipManagerDefaultOptions'); function KbAmazonDropShipManagerDefaultOptions($options) { $options['DropShipManagerLowQuantity'] = 5; $options['DropShipManagerMediumQuantity'] = 20; $options['DropShipManagerLargeQuantity'] = 50; $options['DropShipManagerReminderEmail'] = null; $options['DropShipManagerReminderLow'] = true; $options['DropShipManagerReminderMedium'] = false; $options['DropShipManagerReminderLarge'] = false; $options['DropShipManagerReminderTryScrap'] = true; $options['DropShipManagerDontShowDeleteOnNoQuantity'] = false; $options['DropShipManagerErrors'] = array(); return $options; } add_action('KbAmazonImporter::saveProduct', 'KbAmazonDropShipManagerProductSave'); function KbAmazonDropShipManagerProductSave($std) { if (!getKbAmz()->isCronRunning()) { return; } $postId = $std->postId; $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true); if (!$isDropShipProduct) { return; } $quantity = get_post_meta($postId, 'KbAmzOfferSummary.TotalNew', true); $low = getKbAmz()->getOption('DropShipManagerReminderLow'); if ($low && $quantity <= getKbAmz()->getOption('DropShipManagerLowQuantity')) { KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Low'); return; } $medium = getKbAmz()->getOption('DropShipManagerReminderMedium'); if ($medium && $quantity <= getKbAmz()->getOption('DropShipManagerMediumQuantity')) { KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Medium'); return; } $large = getKbAmz()->getOption('DropShipManagerReminderLarge'); if ($large && $quantity <= getKbAmz()->getOption('DropShipManagerLargeQuantity')) { KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, 'Large'); return; } } function KbAmazonDropShipManagerNotifyForQuantityChange($postId, $quantity, $type) { $lastEmailSentTime = getKbAmz()->getOption('DropShipManagerLastEmailSentTime'); if ($lastEmailSentTime && $lastEmailSentTime + 1800 > time()) { return; } getKbAmz()->setOption('DropShipManagerLastEmailSentTime', time()); $post = get_post($postId); $asin = get_post_meta($post->ID, 'KbAmzASIN', true); $postTitle = $post->post_title; $emails = explode(',', getKbAmz()->getOption('DropShipManagerReminderEmail')); foreach ($emails as $email) { $email = trim($email); $title = '2kb Amazon DropShip Manager Reminder'; $headers = array(); $headers[] = 'From: 2kb Amazon DropShip Manager <'.$email.'>'; $message = "Product with ASIN $asin ($postTitle) has reached quantity of $quantity."; $message .= "\n"; $message .= get_admin_url() . 'admin.php?page=kbAmzDropShipManager&kbAction=manager'; try { $isSent = wp_mail( $email, $title, $message, $headers ); if (!$isSent) { $errors = getKbAmz()->getOption('DropShipManagerErrors'); $errors[] = array( 'date' => date('Y-m-d H:i:s'), 'msg' => 'Mail Send Error: Unknown' ); getKbAmz()->setOption('DropShipManagerErrors', $errors); } } catch (Exception $e) { $errors = getKbAmz()->getOption('DropShipManagerErrors'); $errors[] = array( 'date' => date('Y-m-d H:i:s'), 'msg' => 'Mail Send Error: ' . $e->getMessage() ); getKbAmz()->setOption('DropShipManagerErrors', $errors); } } } add_action('KbAmazonImporter::saveProduct', 'KbAmazonDropShipManagerProductSaveForceScrap', 1); function KbAmazonDropShipManagerProductSaveForceScrap($std) { if (!getKbAmz()->getOption('DropShipManagerReminderTryScrap')) { return; } $postId = $std->postId; $isDropShipProduct = get_post_meta($postId, 'KbAmzDropShipManager', true); if (!$isDropShipProduct) { return; } $postId = $std->postId; $post = get_post($postId); $meta = getKbAmz()->getProductMeta($post->ID, true); if (!isset($meta['KbAmzDetailPageURL'])) { return; } // B00K6DVA8C $urlParts = parse_url($meta['KbAmzDetailPageURL']); $url = sprintf( '%s://%s/dp/%s', $urlParts['scheme'], $urlParts['host'], $meta['KbAmzASIN'] ); $args = array( 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1' ); $content = wp_remote_get($url, $args); if (!is_array($content)) { $content = wp_remote_get($meta['KbAmzDetailPageURL'], $args); } if (!isset($content['body'])) { return; } $content = $content['body']; $meta = array(); $quantityParts = explode('