问题:
我需要一种方法来首先使用特定的优惠券代码进行所有销售.然后从所有销售中获得总收入(最好减去这些销售的任何回报.获得实际收入值).
执行的想法
我正在使用woocommerce 2.6.8和MySql数据库.我的猜测是,我不得不首先计算使用PHP和MySql的特定优惠券的销售数量.然后,对于具有特定优惠券的每个唯一订单ID,对总和进行新查询.
关于如何看待PHP和查询的任何建议都非常感谢:)
我应该指出,我不打算从优惠券中获得折扣的总和.我需要计算与特定优惠券(而不是折扣)一起销售的总价值.
好的,到目前为止仍然没有可行的解决方案.但这就是我认为它的基本结构.获得总数并不容易,因为优惠券与订单没有直接关联.我相信查询必须是这样的:
{} TBLPRFX _woocommerce_order_items
步骤1.获取order_id FOR order_item_name = {COUPON_NAME}
步骤2.获取order_item_id FOR order_item_type = line_item WHERE order_id EQUAL {来自第1步的结果}
| order_item_id | order_item_name | order_item_type | order_id |
| 40971 | {COUPON_NAME} | 优惠券| 001
| 40970 | 增值税| 税| 001
| 40969 | {PRODUCT_NAME} | line_item | 001
-
{} TBLPRFX _woocommerce_order_itemmeta
步骤3. SUM meta_value FROM meta_key = _line_tax AND meta_key = _line_total WHERE order_item_id = {RESULT FROM STEP 2}
| …
在 WooCommerce 中,我已将 woocommerce->settings->products->inventory->stock display format 设置为"Never show amount left in stock"。
但是,如果客户将产品广告到购物车,继续购物车或结账页面并输入高于库存的价格,他们会收到此错误消息:
抱歉,我们没有足够的
{product_name}库存来履行您的订单({available_stock_amount}库存)。请编辑您的购物车并重试。我们对造成的任何不便表示歉意。
我可以使用什么过滤器来编辑此输出?我不希望它显示(绝对在前端商店的任何地方)实际可用库存量。
我发现这是在第 491 行[root]->wp-content->plugins->woocommerce->includes->class-wc-cart.php中的函数 (check_cart_item_stock) 中处理的:
if ( ! $product->has_enough_stock( $product_qty_in_cart[ $product->get_stock_managed_by_id() ] ) ) {
/* translators: 1: product name 2: quantity in stock */
$error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s in stock). Please edit your cart and try again. We apologize for any inconvenience caused.', …Run Code Online (Sandbox Code Playgroud) 在Google API 资源管理器上,我尝试在drive.permissions.create 中提供正确的fileId。我将supportsTeamDrives 设置为true,请求主体的角色为:读者,类型为:任何人。这只是给了我错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidLinkVisibility",
"message": "Bad Request. User message: \"\""
}
],
"code": 400,
"message": "Bad Request. User message: \"\""
}
}
Run Code Online (Sandbox Code Playgroud)
我的 PHP 代码也是如此。这是我能得到的最接近的,对我来说看起来很正确:
...
$userPermission = new Google_Service_Drive_Permission( array(
'type' => 'anyone',
'role' => 'reader',
));
$service->permissions->create( $imageId, $userPermission, array(
'supportsTeamDrives' => true,
));
...
Run Code Online (Sandbox Code Playgroud)
我在错误中找不到任何内容:
无效链接可见性
我需要做的是暂时将文件夹中 20-50 个文件的权限设置为“公共”(即任何知道该链接的人都可以看到它),因为我正在发送 webContentLink(或 webViewLink,我还没有弄清楚我还需要使用哪一个)到另一个 API 来上传图像。完成此操作后,我想删除公共访问权限。一种选择是将文件夹的权限(具有递归公共访问权限)设置为公共访问。我只是不知道如何在 PHP 中更改(或者更确切地说添加)Google Drive API 中文件的权限。
另一种方法是,如果有某种方法可以通过包含令牌的 URL 获取图像,例如
$source = …Run Code Online (Sandbox Code Playgroud) 我对functions.php中的这个简单功能已经足够了解,让我为优惠券添加一个复选框。但是,一旦我保存/更新了优惠券,我的复选框值(已选中/未选中)就不会提交(因此该复选框始终处于未选中状态)。换句话说,当我更新/保存时,无法在postmetas的meta_value列中将其更新为yes。复选框在那里,我就是无法使用...非常沮丧!关于我做错的任何建议,请:)
function add_coupon_revenue_dropdown_checkbox() {
$post_id = $_GET['post'];
woocommerce_wp_checkbox( array( 'id' => 'include_stats', 'label' => __( 'Coupon check list', 'woocommerce' ), 'description' => sprintf( __( 'Includes the coupon in coupon check drop-down list', 'woocommerce' ) ) ) );
$include_stats = isset( $_POST['include_stats'] ) ? 'yes' : 'no';
update_post_meta( $post_id, 'include_stats', $include_stats );
do_action( 'woocommerce_coupon_options_save', $post_id );
}add_action( 'woocommerce_coupon_options', 'add_coupon_revenue_dropdown_checkbox', 10, 0 );
Run Code Online (Sandbox Code Playgroud)
我要影响的部分是:
wp-content / plugins / woocommerce / includes / admin / meta-boxes / class-wc-meta-box-coupon-data.php