Измените download_url в WooCommercePhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Измените download_url в WooCommerce

Сообщение Anonymous »

Я хочу изменить download_url в разделе загрузок моей учетной записи в WooCommerce Поэтому я изменил home_url( '/' ) на home_url( '/account/downloads/' ), используя приведенный ниже крючок:

Код: Выделить всё

function filter_woocommerce_customer_available_downloads( $downloads, $customer_id ) {
$downloads   = array();
$_product    = null;
$order       = null;
$file_number = 0;

// Get results from valid orders only.
$results = wc_get_customer_download_permissions( $customer_id );

if ( $results ) {
foreach ( $results as $result ) {
$order_id = intval( $result->order_id );

if ( ! $order || $order->get_id() !== $order_id ) {
// New order.
$order    = wc_get_order( $order_id );
$_product = null;
}

// Make sure the order exists for this download.
if ( ! $order ) {
continue;
}

// Check if downloads are permitted.
if ( ! $order->is_download_permitted() ) {
continue;
}

$product_id = intval( $result->product_id );

if ( ! $_product || $_product->get_id() !== $product_id ) {
// New product.
$file_number = 0;
$_product    = wc_get_product( $product_id );
}

// Check product exists and has the file.
if ( ! $_product || ! $_product->exists() || ! $_product->has_file( $result->download_id ) ) {
continue;
}

$download_file = $_product->get_file( $result->download_id );

// If the downloadable file has been disabled (it may be located in an untrusted location) then do not return it.
if ( ! $download_file->get_enabled() ) {
continue;
}

// Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files.
$download_name = apply_filters(
'woocommerce_downloadable_product_name',
$download_file['name'],
$_product,
$result->download_id,
$file_number
);

$downloads[] = array(
'download_url'        => add_query_arg(
array(
'download_file' => $product_id,
'order'         => $result->order_key,
'email'         => rawurlencode( $result->user_email ),
'key'           => $result->download_id,
),
home_url( '/account/downloads/' )
),
'download_id'         => $result->download_id,
'product_id'          => $_product->get_id(),
'product_name'        => $_product->get_name(),
'product_url'         => $_product->is_visible() ? $_product->get_permalink() : '', // Since 3.3.0.
'download_name'       => $download_name,
'order_id'            => $order->get_id(),
'order_key'           => $order->get_order_key(),
'downloads_remaining' => $result->downloads_remaining,
'access_expires'      => $result->access_expires,
'file'                => array(
'name' => $download_file->get_name(),
'file' => $download_file->get_file(),
),
);

$file_number++;
}
}
return $downloads;
} add_filter( 'woocommerce_customer_available_downloads', 'filter_woocommerce_customer_available_downloads', 10, 2 );
Код основан на функции wc_get_customer_available_downloads( $customer_id ), которую можно найти в файле /includes/wc-user-functions.php
Можно ли обобщить крючок?

Подробнее здесь: https://stackoverflow.com/questions/724 ... oocommerce
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»