I want a discount 11% on specific products that have a published year after 2016 in my woocommerce eshop.
This field (pub_year) is a custom field in a custom table with the name fancyplugin_wc_product_info
in the wpdb.
I tried some code(which is a mixed code from a research I made) with no success.
The code that I tried:
function get_price_multiplier() {
return 100; // 100 the multiplier
}
function get_price_discount() {
return 11; // 11% discount
}
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_get_sale_price', 'custom_price', 99, 2 );
function custom_price( $price, $product ) {
global $woocommerce, $post, $wpdb;
$table_name = $wpdb->prefix . 'fancyplugin_wc_product_info';
$result = ("SELECT * FROM {$table_name} WHERE pub_year >= '2016'");
if( $result ) {
$price = $price - (get_price_discount() / get_price_multiplier() * $price);
}
return $price;
}