admin管理员组文章数量:1323342
Im using woocommerce for a website and where the client sells software. One of the options I have to add is request a license button on my account page.
I already have the function that does this in a file request-license.php in the woocommerce folder in my theme but I'm having problems to add a new point.
when you click view the endpoint calls view-order.php file so I want to call request-license when the request license button is clicked.
here is how is called
<?php
$actions = array();
if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order ) ) ) {
$actions['pay'] = array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' )
);
}
if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
$actions['cancel'] = array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
);
}
$actions['license'] = array(
'url' => $order->get_request_license_url(),
'name' => __( 'Request License', 'woocommerce' )
);
$actions['view'] = array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' )
);
$actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order );
if ( $actions ) {
foreach ( $actions as $key => $action ) {
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
}
}
?>
I know I have to create the get_request_license_url() function but not sure how to implement it. Hope I can have some help here
Im using woocommerce for a website and where the client sells software. One of the options I have to add is request a license button on my account page.
I already have the function that does this in a file request-license.php in the woocommerce folder in my theme but I'm having problems to add a new point.
when you click view the endpoint calls view-order.php file so I want to call request-license when the request license button is clicked.
here is how is called
<?php
$actions = array();
if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order ) ) ) {
$actions['pay'] = array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' )
);
}
if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
$actions['cancel'] = array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
);
}
$actions['license'] = array(
'url' => $order->get_request_license_url(),
'name' => __( 'Request License', 'woocommerce' )
);
$actions['view'] = array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' )
);
$actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order );
if ( $actions ) {
foreach ( $actions as $key => $action ) {
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
}
}
?>
I know I have to create the get_request_license_url() function but not sure how to implement it. Hope I can have some help here
Share Improve this question edited Dec 11, 2015 at 13:40 Pieter Goosen 55.4k23 gold badges115 silver badges210 bronze badges asked Sep 1, 2015 at 17:02 user3344329user3344329 711 gold badge1 silver badge3 bronze badges 1- You can get your answer from this link. github/woocommerce/woocommerce/wiki/… – vijay Commented Feb 22, 2017 at 12:29
1 Answer
Reset to default 6seems woocommerce doesn't have any filters when registering their endpoints, https://github/woothemes/woocommerce/blob/master/includes/class-wc-query.php#L84
so you need to add your new endpoint on init hooks, just like this
add_action( 'init', 'add_endpoint' );
function add_endpoint(){
add_rewrite_endpoint( 'license', EP_ROOT | EP_PAGES );
}
then you have to do some filtering on wc_get_template
to call your files when the request match your endpoint
add_filter( 'wc_get_template', 'custom_endpoint', 10, 5 );
function custom_endpoint($located, $template_name, $args, $template_path, $default_path){
if( $template_name == 'myaccount/my-account.php' ){
global $wp_query;
if(isset($wp_query->query['license'])){
$located = get_template_directory() . '/your-path-to-file.php';
}
}
return $located;
}
so when you visit my account page with endpoint license
,
let say http://yourdomain/my-account/license/
, that will display your custom code
本文标签: How to add a new endpoint in woocommerce
版权声明:本文标题:How to add a new endpoint in woocommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742134950a2422327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论