通过 WooCommerce 3 中的 Hook 更改产品价格
WooCommerce 插件提供了一种通过使用 Hook 修改产品价格的便捷方法。这允许根据各种标准进行动态价格调整。但是,在尝试更改 WooCommerce 3 中的变体价格时会出现问题。
原始方法和限制
要修改所有产品价格(包括变体),可以使用以下挂钩使用:
add_filter('woocommerce_get_price', array( $this, 'my_custom_price'), 99); add_filter('woocommerce_get_regular_price', array( $this, 'my_custom_price'), 99);
不幸的是,这些钩子不能有效地处理变化产品。
变体产品解决方案
要成功修改 WooCommerce 3 中的变体价格,请使用以下 PHP 代码:
// Simple, grouped and external products add_filter('woocommerce_product_get_price', array( $this, 'custom_price' ), 99, 2 ); add_filter('woocommerce_product_get_regular_price', array( $this, 'custom_price' ), 99, 2 ); // Variations add_filter('woocommerce_product_variation_get_regular_price', array( $this, 'custom_price' ), 99, 2 ); add_filter('woocommerce_product_variation_get_price', array( $this, 'custom_price' ), 99, 2 ); // Variable (price range) add_filter('woocommerce_variation_prices_price', array( $this, 'custom_variable_price' ), 99, 3 ); add_filter('woocommerce_variation_prices_regular_price', array( $this, 'custom_variable_price' ), 99, 3 );
缓存价格和 WooCommerce 3
WooCommerce 3 引入了变体的缓存价格。要在价格调整时有效刷新缓存价格,请使用以下挂钩:
add_filter( 'woocommerce_get_variation_prices_hash', array( $this, 'add_price_multiplier_to_variation_prices_hash' ), 99, 3 );
价格过滤小部件挂钩
要使用小部件过滤产品价格,请使用以下钩子:
woocommerce_price_filter_widget_min_amount woocommerce_price_filter_widget_max_amount
以上是如何在 WooCommerce 3 中动态更改产品和变体价格?的详细内容。更多信息请关注PHP中文网其他相关文章!

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)

phpisusedforsenderemailsduetoitsbuilt-inmail()函数andsupportiveLibrariesLikePhpMailerandSwiftMailer.1)usethemail()functionforbasicemails,butithasimails.2)butithasimimitations.2)

PHP性能瓶颈可以通过以下步骤解决:1)使用Xdebug或Blackfire进行性能分析,找出问题所在;2)优化数据库查询并使用缓存,如APCu;3)使用array_filter等高效函数优化数组操作;4)配置OPcache进行字节码缓存;5)优化前端,如减少HTTP请求和优化图片;6)持续监控和优化性能。通过这些方法,可以显着提升PHP应用的性能。

依赖性注射(DI)InphpisadesignPatternthatManages和ReducesClassDeptions,增强量产生性,可验证性和Maintainability.itallowspasspassingDepentenciesLikEdenceSeconnectionSeconnectionStoclasseconnectionStoclasseSasasasasareTers,interitationApertatingAeseritatingEaseTestingEasingEaseTeStingEasingAndScalability。

cachingimprovesphpermenceByStorcyResultSofComputationsorqucrouctationsorquctationsorquickretrieval,reducingServerLoadAndenHancingResponsetimes.feftectivestrategiesinclude:1)opcodecaching,whereStoresCompiledSinmememorytssinmemorytoskipcompliation; 2)datacaching datacachingsingMemccachingmcachingmcachings


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver Mac版
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版
中文版,非常好用

SublimeText3 英文版
推荐:为Win版本,支持代码提示!