2014-02-18 64 views
-1

因此,我想修改可以在WC_Customer类中找到的get_downloadable_products()产生的输出。如何扩展WC_Customer

我原来虽然是扩展WC_Customer,所以我创建以下文件夹/wp-content/themes/my-theme/woocommerce/classes/class-wc-customer.php

内键入此:

类WC_Customer_Custom扩展WC_Customer {

修改的输出,但不能看到我的网站上的任何变化。

有人可以让我知道我该怎么做?

+0

巨魔警报,后倒在前进的投票! – user30899

回答

0

你不扩展类。 Woocommerce会忽略它们。你必须使用add_filter()或add_action()在wordpress中做些东西。

正如你可以read in function它调用名为过滤器:woocommerce_customer_get_downloadable_products

add_filter('woocommerce_customer_get_downloadable_products', 'modify_downloads'); 
function modify_downloads($downloads) { 
    // do stuff with $downloads array 
    return $downloads; 
} 
+0

谢谢你的回复。实际上,我确实最终扩展了一个WC_Customer类并成功地重写了一个函数。工作正常!:D – user30899