add_filter('woocommerce_before_cart_item_quantity_zero', 'wordpress_before_cart_item_quantity_zero', 10, 1);
function wordpress_before_cart_item_quantity_zero($item) {
global $wpdb;
global $woocommerce;
$cart = $woocommerce->cart;
foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
$id_product = $cart_item['product_id'];
$wpdb->prepare("DELETE FROM wp_block_product WHERE product_id = %d", $id_product);
$preparing_query = $wpdb->query($preparing_query);
}
var_dump($wpdb);
exit;
}
但是当我从购物车中删除商品时,它无效!
我试着这样做:
add_action('woocommerce_before_cart_item_quantity_zero', 'wordpress_before_cart_item_quantity_zero');
但它也不起作用
答案 0 :(得分:3)
根据the source,您正在寻找'woocommerce_cart_item_removed'
,它会在商品从购物车中移除时运行:
function so31115243_after_remove_product($cart_item_key) {
// Your custom function
}
add_action( 'woocommerce_cart_item_removed', 'so31115243_after_remove_product' );
答案 1 :(得分:0)
在删除项目之前还有一个挂钩,即<?xml version="1.0" encoding="UTF-8"?><!--File RemoteFiles/GeographicalDesignStructure.wsdl, static library AFPServiciosExportComun_LIB--><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="GeographicalDesignStructure" targetNamespace="[this is not a link]http://company.com/GeographicalDesignStructure/wsdl/1.0/_MM/" xmlns:bons1="[this is not a link]http://company.com/GeographicalDesignStructure/paisConsulta/schema/1.0/" xmlns:bons2="[this is not a link]http://company.com/GeographicalDesignStructure/regionConsulta/schema/1.0/" xmlns:tns="[this is not a link]http://company.com/GeographicalDesignStructure/wsdl/1.0/_MM/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:documentation>
<wsdl:appinfo source="WMQI_APPINFO">
<MRWSDLAppInfo imported="true">
<generatedXSD location="GeographicalDesignStructure_InlineSchema1.xsd"/>
</MRWSDLAppInfo>
</wsdl:appinfo>
</wsdl:documentation>
<wsdl:types>
<xsd:schema targetNamespace="[this is not a link]http://company.com/GeographicalDesignStructure/wsdl/1.0/_MM/" xmlns:bons0="http://company.com/ZonaGeograficaConsultaSalida/schema/V1/" xmlns:bons4="[this is not a link]http://company.com/GeographicalDesignStructure/ZonaGeograficaConsultaEntrada/schema/1/" xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions">
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ZonaGeograficaConsultaEntrada/schema/1/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd0"/>
<xsd:import namespace="http://company.com/ZonaGeograficaConsultaSalida/schema/V1/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd1"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/regionConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd2"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/regionConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd3"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/paisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd4"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/paisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd5"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaPaisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd6"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaPaisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd7"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaPaisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd6"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaPaisConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd7"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaRegionConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd8"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaRegionConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd9"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaZonaGeograficaConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd10"/>
<xsd:import namespace="[this is not a link]http://company.com/GeographicalDesignStructure/ListaZonaGeograficaConsulta/schema/1.0/" schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd11"/>
<xsd:include schemaLocation="https://vaxtpmde71:444/GeographicalDesignStructure_MMWeb/sca/wsGeographicalDesignStructure?xsd=xsd12"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="paisConsultaResponseMsg">
<wsdl:part element="tns:paisConsultaResponse" name="paisConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:message name="regionConsultaRequestMsg">
<wsdl:part element="tns:regionConsulta" name="regionConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="regionConsultaResponseMsg">
<wsdl:part element="tns:regionConsultaResponse" name="regionConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:message name="zonaGeograficaConsultaRequestMsg">
<wsdl:part element="tns:zonaGeograficaConsulta" name="zonaGeograficaConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="paisConsultaRequestMsg">
<wsdl:part element="tns:paisConsulta" name="paisConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="zonaGeograficaConsultaResponseMsg">
<wsdl:part element="tns:zonaGeograficaConsultaResponse" name="zonaGeograficaConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:message name="CacheXXXXRequestMsg">
<wsdl:part element="tns:CacheXXXX" name="CacheXXXXParameters"/>
</wsdl:message>
<wsdl:message name="CacheXXXXResponseMsg">
<wsdl:part element="tns:CacheXXXXResponse" name="CacheXXXXResult"/>
</wsdl:message>
<wsdl:message name="listaPaisConsultaRequestMsg">
<wsdl:part element="tns:listaPaisConsulta" name="listaPaisConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listaPaisConsultaResponseMsg">
<wsdl:part element="tns:listaPaisConsultaResponse" name="listaPaisConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listaRegionConsultaRequestMsg">
<wsdl:part element="tns:listaRegionConsulta" name="listaRegionConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listaRegionConsultaResponseMsg">
<wsdl:part element="tns:listaRegionConsultaResponse" name="listaRegionConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listaZonaGeograficaConsultaRequestMsg">
<wsdl:part element="tns:listaZonaGeograficaConsulta" name="listaZonaGeograficaConsultaParameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listaZonaGeograficaConsultaResponseMsg">
<wsdl:part element="tns:listaZonaGeograficaConsultaResponse" name="listaZonaGeograficaConsultaResult">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="GeographicalDesignStructure">
<wsdl:operation name="paisConsulta">
<wsdl:input message="tns:paisConsultaRequestMsg" name="paisConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:paisConsultaResponseMsg" name="paisConsultaResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="regionConsulta">
<wsdl:input message="tns:regionConsultaRequestMsg" name="regionConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:regionConsultaResponseMsg" name="regionConsultaResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="zonaGeograficaConsulta">
<wsdl:input message="tns:zonaGeograficaConsultaRequestMsg" name="zonaGeograficaConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:zonaGeograficaConsultaResponseMsg" name="zonaGeograficaConsultaResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CacheXXXX">
<wsdl:input message="tns:CacheXXXXRequestMsg" name="CacheXXXXRequest"/>
<wsdl:output message="tns:CacheXXXXResponseMsg" name="CacheXXXXResponse"/>
</wsdl:operation>
<wsdl:operation name="listaPaisConsulta">
<wsdl:input message="tns:listaPaisConsultaRequestMsg" name="listaPaisConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:listaPaisConsultaResponseMsg" name="listaPaisConsultaResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="listaRegionConsulta">
<wsdl:input message="tns:listaRegionConsultaRequestMsg" name="listaRegionConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:listaRegionConsultaResponseMsg" name="listaRegionConsultaResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="listaZonaGeograficaConsulta">
<wsdl:input message="tns:listaZonaGeograficaConsultaRequestMsg" name="listaZonaGeograficaConsultaRequest">
</wsdl:input>
<wsdl:output message="tns:listaZonaGeograficaConsultaResponseMsg" name="listaZonaGeograficaConsultaResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
。
我相信这是Danya在上述评论中所寻求的,以防任何人遇到类似的问题。
答案 2 :(得分:0)
@rnevius解决方案有效,但需要更改操作的优先级。对我来说这是21,但我认为它可以改变插件使用它。
add_action( 'woocommerce_cart_item_removed', 'so31115243_after_remove_product', 21 );