Woocommerce display downloadable files with an external url - wordpress

I need help with this: I need that the url of the downloadable products link with an external url. I´m trying to add a custom field and replace the filters woocommerce_product_file and woocommerce_product_file_download_path but it didn't worked, I think because I can´t call to the product data from the order. Someone did this? Thank you for your help!
The code doesn't works. Now is something like:
*function mostrar_campo_personalizado_en_order($file_id){
global $wpdb, $woocommerce;
echo get_post_meta($file_id, 'downloadable_url', true);
}
add_filter( 'woocommerce_product_file', 'mostrar_campo_personalizado_en_order', 10, 1 );
add_filter( 'woocommerce_product_file_download_path', 'mostrar_campo_personalizado_en_order', 10, 1 );*
I don´t know if I´m working in the correct way, I need to change the url of the downloadable products because woocommerce internally routed. Because I couldn't modify him, I intente removal and display a custom post field. The page is in a test server because the site is on line. The url of the tester server ishttp://lab.jus.raffles.com.ar/my-account/ but you need credential to come in:
user: paula
pass: 5VPeGgAHWzYX1T

Related

Which hook do I use, to redirect user based on post/category?

I'm new to WP development. I need to write a hook to check if the currently logged in user is viewing a post listed within a specific category, and then redirect user if they're lacking certain meta data.
I tried creating this function:
add_action('init','check_user_post_category');
however inside that function I was unable to get the post object (I have tried everything I found on the web!)
global $post; // This object is not valid at this time
global $wp; // $wp->request is empty
$_REQUEST; // This var is giving me an empty array! Is this normal??? :(
Could you kindly suggest, what hook is best to use in this case, and how to get the post object? Many thanks!
Use 'wp' hook instead of 'init'.
add_action('wp','check_user_post_category');
Maybe this would work for you.

How to get permalink to a specific WooCommerce endpoint?

Hi I am looking how to get a permalink to a woocommerce my account page endpoint. For example edit-address or orders.
I tried this which I know can't possibly be right, it also appends a 0 onto the end of the link.
get_permalink( get_option('woocommerce_myaccount_page_id') )+"orders";
You should use wc_get_endpoint_url(), it will get endpoint value you set in Woocommerce settings so if you change it one day, your URLs will be updated.
wc_get_endpoint_url('orders', '', get_permalink(get_option('woocommerce_myaccount_page_id')))
Available endpoints are :
view-order
edit-account
dashboard
orders
downloads
edit-address
payment-methods
customer-logout
Replace your code with this
get_permalink( get_option('woocommerce_myaccount_page_id') ) . "orders";
PHP concatenation is dot symbol not plus symbol. https://stackoverflow.com/a/1866194/1593365. Your code seems right only

Wordpress and Woocmmerce - how to access settings from theme?

Im trying to pull the settings from Woocommerce admin. I found this:
http://oik-plugins.eu/woocommerce-a2z/oik_api/woocommerce_settings_get_option/
$string = woocommerce_settings_get_option( $option_name, $default );
It looks to be a public function but I cannot access from my theme files. It just gives me Fatal error: Call to undefined. Anyone have any idea how you can access the setting from the theme?
I'm trying to get 'woocommerce_frontend_css_primary', $colors['primary'] so can tie them into the rest of the theme. Woocommerce currently just write the values directly to .less file.
Woocommerce docs are a bit misleading, but it turns out there is another function called get_option... as long as you know the name of the option you can use. EG. get array of front end colors:
$woo_styles = get_option( 'woocommerce_frontend_css_colors' );

Wordpress URL rewrite not working/registering

I've been trying to get my head around Wordpress URL rewrites, but I'm having no luck.
What I want to do:
I building a custom plugin where a user can build products from various options. The options collectively build a code which refers to the unique product the customer has built.
The code might be something like 140-3-WPA-ABC-2.
The plugin will appear on a single dedicated page:
http://wordpress-site/configurator/
I want a customer with a prexisiting code to be able to enter it into the url like this:
http://wordpress-site/configurator/140-3-WPA-ABC-2/
Whereupon, the plugin gets the variable, and uses it to build the correct product.
Problem
It should be fairly simply but I can't get anything to work using the Wordpress URL rewriting rules, I can't even get anything to seemingly get registered as a Wordpress query var.
I've been trying the following in the main plugin initialisation code:
add_filter( 'query_vars', 'conf_query_vars' );
add_action( 'init', 'cong_rewrites' );
function conf_query_vars($query_vars){
$query_vars[] = 'product_code';
return $query_vars;
}
function conf_rewrites(){
add_rewrite_rule(
'configurator/([^/]+)/?$',
'index.php?product_code=$matches[1]',
'top'
);
}
If I then try and open http://wordpress-site/configurator/140-3-WPA-ABC-2/ I get a page not found error. Echoing query_vars seems to show the variable 'product_code' is not created.
ps I've tried flushing the rewrite cache. Apologies for cross-posting to Wordpress.stackexchange.com - but seems programming question better here?
Try this, I had the same problem.
add_action('init', function() {
add_rewrite_endpoint('sponsor', EP_ALL);
});
add_filter('request', function($args) {
print_r($args);
return $args;
});
I think you should just integrate the function add_rewrite_endpoint.

Wordpress permalink without domain name

OK it might sound stange but I am facing a good challenge with wordpress.
when echoing the_permalink(); and checking the portfolio pages, I am getting a link something like this:
http://www.domain.com/?portfolio=test
(Where test is the portfolio name).
Is there any option to return the permalink trimmed to ?portfolio=test keeping out the domain url?
While asking, I think I got the answer already (trim()) but I would like to hear your ideas too.
every answer will be much appreciated!
You can obtain the permalink of a post by doing something like so:
<?php
function my_permalink() {
echo substr(get_permalink(), strlen(get_option('home')));
}
?>
The get_option method replaces the deprecated get_settings method, and allows you to retrieve named option values from the database:
http://codex.wordpress.org/Function_Reference/get_option
The 'home' value passed in to the get_option method will return the site URL.

Resources