Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 商业交叉销售的分类_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 商业交叉销售的分类

Php 商业交叉销售的分类,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想按日期或其他参数对woocommerce交叉销售的产品进行排序。现在产品按字母顺序展示。我找到了一个解决方案: add_filter( 'woocommerce_cross_sells_orderby', 'custom_cross_sells_orderby', 10, 1 ); function custom_cross_sells_orderby( $orderby ){ $orderby = 'date'; return $orderby; } 但当我在me fun

我想按日期或其他参数对woocommerce交叉销售的产品进行排序。现在产品按字母顺序展示。我找到了一个解决方案:

add_filter( 'woocommerce_cross_sells_orderby', 'custom_cross_sells_orderby', 10, 1 );
function custom_cross_sells_orderby( $orderby ){
    $orderby = 'date';
    return $orderby;
}

但当我在me functions.php中添加此代码时,会出现错误505。可能是你知道为什么吗?或者你知道其他的解决方案吗?谢谢。

只需在主题文件夹中名为functions.php的文件中添加以下代码:

<?php
// Filters

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
add_filter( 'woocommerce_cross_sells_orderby', 'custom_woocommerce_catalog_orderby' );

 // Apply custom args to main query
function custom_woocommerce_get_catalog_ordering_args( $args ) {
    $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );

    if ( 'oldest_to_recent' == $orderby_value ) {
        $args['orderby'] = 'date';
        $args['order'] = 'ASC';
    }

    return $args;
}

// Create new sorting method
function custom_woocommerce_catalog_orderby( $sortby ) {

    $sortby['oldest_to_recent'] = __( 'Oldest to most recent', 'woocommerce' );

    return $sortby;
}